怎样实现鼠标滑过不滚动移出继续滚动呢?
对于setTimeout进行清除好像不起作用啊,老师求解答
对于setTimeout进行清除好像不起作用啊,老师求解答
2015-05-04
window.onload= function () { var oMain=document.getElementById('main'); var iLineHeight=20; //滚高高度 oMain.innerHTML+=oMain.innerHTML; oMain.scrollTop=0; var timer; var can=false; var move; function startMove(){ oMain.scrollTop++; timer=setInterval(scrollUp,50); } function scrollUp(){ if(oMain.scrollTop%iLineHeight==0){ clearInterval(timer); if(!can) { setTimeout(startMove, 2000) } }else{ oMain.scrollTop++; if(oMain.scrollTop>=oMain.scrollHeight/2){ oMain.scrollTop=0; } } } move=setTimeout(startMove,2000); oMain.onmouseenter= function () { can=true; } oMain.onmouseleave= function () { can=false; if(move){ clearTimeout(move); } move=setTimeout(startMove,2000); } }
举报