滚动条移动过程中,鼠标滚轮的影响。
感谢老师的讲解,受益匪浅。但是在ScrollTop到0的过程中,如果向下滚动鼠标滚轮,滚动条会一直向顶部滚动。所以我想到了在函数中屏蔽鼠标滚轮事件(window.onmousewheel=function(){return false};)。当清空定时器的时候,将事件恢复(window.onmousewheel=function(){return true};),不知道老师还有没有其他办法解决此类问题。

感谢老师的讲解,受益匪浅。但是在ScrollTop到0的过程中,如果向下滚动鼠标滚轮,滚动条会一直向顶部滚动。所以我想到了在函数中屏蔽鼠标滚轮事件(window.onmousewheel=function(){return false};)。当清空定时器的时候,将事件恢复(window.onmousewheel=function(){return true};),不知道老师还有没有其他办法解决此类问题。

2015-06-17
window.onload= function(){
var obtn = document.getElementById('btn');
var timer=null;
obtn.onclick=function(){
timer= setInterval(function(){
var osTop= document.documentElement.scrollTop || document.body.scrollTop;
var ispeed = Math.floor(-osTop/6);
document.documentElement.scrollTop=document.body.scrollTop=osTop + ispeed;
console.log("osTop:" + (osTop));
console.log("ispeed:"+(ispeed));
// console.log("top:" + (top));
window.onmousewheel=function(){clearInterval(timer);};
if (osTop==0) {
clearInterval(timer);
// window.onmousewheel=function(){return true};
};
},20);
}
}已解决,在滚动过程中,滚动滚轮,触发清空定时器操作。
举报