js 鼠标双击滚动单击停止
<!DOCTYPE html> <html> <head> <title>双击滚动代码</title> <script src="http://libs.baidu.com/jquery/1.9.0/jquery.js"></script> </head> <body> <button id="a1">-</button> <input type="number" id="t1" disabled="disabled" value="0" style="text-align:center;"> <button id="j1">+</button> <hr/> <hr/> <button id="a2">-</button> <input type="number" id="t2" disabled="disabled" value="0" style="text-align:center;"> <button id="j2">+</button> <div style="height:1500px;"> </div> <script> var currentpos,timer; function initialize() { timer=setInterval("scrollwindow()",3); } function sc(){ clearInterval(timer); } function scrollwindow(){ if(document.body.scrollTop){//加了DTD头时,document.body.scrollTop值始终为0,在此判断一下 currentpos=document.body.scrollTop; window.scroll(0,++currentpos); if (currentpos != document.body.scrollTop){ sc(); } } else{ currentpos=document.documentElement.scrollTop; window.scroll(0,++currentpos); if (currentpos != document.documentElement.scrollTop){ sc(); } } } document.onmousedown=sc document.ondblclick=initialize </script> </body> </html>
人如代码,规矩灵活;代码如诗,字句精伦。