Js双击滚屏代码

来源:互联网 发布:金盾软件下载 编辑:程序博客网 时间:2024/05/01 04:21

<!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=utf-8" />
  <title>双击滚屏</title>
 </head>
<body>
<script type="text/javascript">
 //创建测试内容
 for(var i=0;i<200;i++){
  document.write(i+'<br/>');
 }
</script>
<script type="text/javascript">
 (function(win){
  var curY = 0,lasY = 0,type = 0,doc = win.document,body = doc.body,realHeight = 0,timer,rbody = doc.documentElement;
  //兼容性检测
  document.onreadystatechange = function(){  
          if(document.readyState=="complete") {  
        test();
          }
  }
  //核心滚动函数
  function scroll(){
   //兼容IE
   0 == type ? lasY = body.scrollTop : lasY = rbody.scrollTop;
   window.scroll(0,++lasY);
   0 == type ? curY = body.scrollTop : curY = rbody.scrollTop;
   if(lasY != curY){//已经滚动到最后
    //alert('over!');
    clearInterval(timer);
   }
  }
  //滚动事件绑定
  doc.ondblclick = function(){
   timer = setInterval(scroll,40);
  };
  //清除滚动
  doc.onmousedown = function(){
   clearInterval(timer);
  }
  //兼容性能力测试函数
  function test(){
   var temp = body.scrollTop;
   ++body.scrollTop;
   if(body.scrollTop == temp){
    type = 1;
   }
   body.scrollTop--;
  }
 })(window);

</script>
 
</body>
</html>

原创粉丝点击