js 鼠标双击滚动单击停止

时间:2025-03-13 16:06:25
<!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="" style="text-align:center;">
<button id="j1">+</button>
<hr/>
<hr/>
<button id="a2">-</button>
<input type="number" id="t2" disabled="disabled" value="" style="text-align:center;">
<button id="j2">+</button> <div style="height:1500px;">
</div> <script> var currentpos,timer;
function initialize()
{
timer=setInterval("scrollwindow()",);
}
function sc(){
clearInterval(timer);
}
function scrollwindow(){
if(document.body.scrollTop){//加了DTD头时,document.body.scrollTop值始终为0,在此判断一下
currentpos=document.body.scrollTop;
window.scroll(,++currentpos);
if (currentpos != document.body.scrollTop){
sc();
}
}
else{
currentpos=document.documentElement.scrollTop;
window.scroll(,++currentpos);
if (currentpos != document.documentElement.scrollTop){
sc();
}
}
} document.onmousedown=sc
document.ondblclick=initialize </script>
</body>
</html>