티스토리 뷰

Javascript

따라다니는 날개 배너

잠덜 2011. 3. 14. 20:45

<script>
 String.prototype.toInteger = function() {return this.replace(/[^0-9]/g, '') * 1;}
 function follow_banner(div_id, origin_top, limit_top, margin_top){
  var d, t, s, g, target_height;
  origin_top *= 1;
  limit_top *= 1;
  margin_top *= 1;
  d = document.getElementById(div_id);
  s = document.body.scrollTop + "";
  target_height = s.toInteger() + margin_top;
  if(target_height < limit_top)
   target_height = origin_top;
   t = d.style.top.toInteger();
  if(t != target_height) {
   g = Math.ceil((t - target_height) / 5);
   if(g > 50) g = 50;
   else if (g < -50)  g = -50;
  
   d.style.top = (t - g) + "px";
  }
  setTimeout("follow_banner('" + div_id + "', " + origin_top + ", " + limit_top + ", " + margin_top + ");", 1);
 }
</script>

<div id="banner" style="position:absolute;z-index:99;left:50%;margin-left:490px;"></div>


<script>
b = document.getElementById("banner");
//follow_banner("banner", b.style.top.toInteger() + 175, b.style.top.toInteger() + 170, 10);
follow_banner("banner", b.style.top.toInteger() + 175, b.style.top.toInteger() + 170, 10);
//follow_banner("배너아이디", 원래의 위치, 따라다니기 시작하는 높이, 화면 위쪽마진);
</script>
댓글

공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/03   »
1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28 29 30
31
글 보관함