티스토리 뷰

Javascript

따라다니는 날개 배너

잠덜 2011.03.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>
저작자 표시
신고
댓글
댓글쓰기 폼