实现随页面滚动的层(最简单效果)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>

</head>

<body>
   <div id="sorollDiv1" style="width:30px; height:50px; background-color:#0000ff; right:10px;position:absolute;top:120px;"></div>
 <script type="text/javascript">
 var lastScrollY=0;
 function heartBeat(){
  diffY=document.documentElement.scrollTop;
  percent=0.1*(diffY-lastScrollY);
  if(percent>0)percent=Math.ceil(percent);
  else percent=Math.floor(percent);
  document.getElementById("sorollDiv1").style.top=parseInt(document.getElementById("sorollDiv1").style.top)+percent+"px";
  lastScrollY=lastScrollY+percent;
 }
 window.setInterval("heartBeat()",1);
</script>
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
    <br />
</body>
</html>

posted on 2007-08-29 17:22  挖豆  阅读(1153)  评论(0编辑  收藏  举报