随页面滚动的层(转)

Posted on 2006-06-13 14:02  joinsky  阅读(1536)  评论(1)    收藏  举报

drop.js文件的内容
self.onError=null;   
currentX = currentY = 0;   
whichIt = null;   
lastScrollX = 0; //最后离左边距离的负值
lastScrollY =0;  //最后离顶部的高度的负值
 
//----------------------start fun秒执行一次  
function heartBeat(id1,id2) {   
diffY = document.body.scrollTop;
diffX = document.body.scrollLeft;

if(diffY != lastScrollY) {   
percent = .1 * (diffY - lastScrollY);   
if(percent > 0) percent = Math.ceil(percent);   
else percent = Math.floor(percent);   
id1.style.pixelTop += percent;
id2.style.pixelTop += percent;  
lastScrollY = lastScrollY + percent;   
}   

if(diffX != lastScrollX) {   
percent = .1 * (diffX - lastScrollX);   
if(percent > 0) percent = Math.ceil(percent);   
else percent = Math.floor(percent);   
id1.style.pixelTop += percent;
id2.style.pixelTop += percent;     
lastScrollX = lastScrollX + percent;   
}   
}   
//-----------------------end fun
scr=screen.width
left_1=(scr>800)?10:145
right_1=(scr>800)?880:580

//左侧图片
document.write("<DIV id=f1 style='left: "+left_1+"px; top: 460px; POSITION: absolute;'><a href='#' target=_blank><img src='041.gif' border=0 width=120 height=125></a></div>")

//右侧图片
document.write("<DIV id=f2 style='left: "+right_1+"px; top: 215px; POSITION: absolute;'><a href='#' target=_blank><img src='011.gif' border=0 width=150 height=47></a></div>")

action = window.setInterval("heartBeat(f1,f2)",1);  

1.html代码:
<html>
<head>
<script src="drop.js" language="javascript">
</script>
</head>
<body>
<table>
 <tr>
  <td height=10278px>
  </td>
 </tr>

</table>
asdf
</body>
</html>

博客园  ©  2004-2026
浙公网安备 33010602011771号 浙ICP备2021040463号-3