这是我的代码
<script>
var act = 0;
var y = 0;
var mousewheelevt = (/Firefox/i.test(navigator.userAgent)) ? "DOMMouseScroll" : "mousewheel" //FF doesn't recognize mousewheel as of FF3.x
$(window).bind(mousewheelevt, function(e){
var evt = window.event || e //equalize event object
evt = evt.originalEvent ? evt.originalEvent : evt; //convert to originalEvent if possible
var delta = evt.detail ? evt.detail*(-40) : evt.wheelDelta //check for detail first, because it is used by Opera and FF
if(delta > 0) {
console.log('nahoru stop y=0 act=0');
y = 0;
pageScrollStart(y);
act = 0;
}
else{
if(act==1)
{
console.log('dolu aktivni nic');
}
else
{
console.log('dolu neaktivni start y=1 act=1');
y = 1;
pageScrollStart(y);
act = 1;
}
}
});
function pageScrollStart() {
window.scrollBy(0,y);
scrolldelay = setTimeout('pageScrollStart()',50);
};
</script>
答案 0 :(得分:0)
解决了..我只是不知道函数&#34; clearTimeout&#34;
所以现在它看起来像这样:
<script>
var act = 0;
var mousewheelevt = (/Firefox/i.test(navigator.userAgent)) ? "DOMMouseScroll" : "mousewheel" //FF doesn't recognize mousewheel as of FF3.x
$(window).bind(mousewheelevt, function(e){
var evt = window.event || e //equalize event object
evt = evt.originalEvent ? evt.originalEvent : evt; //convert to originalEvent if possible
var delta = evt.detail ? evt.detail*(-40) : evt.wheelDelta //check for detail first, because it is used by Opera and FF
if(delta > 0) {
pageScrollStop();
console.log('nahoru stop');
act = 0;
}
else{
if(act !== 1)
{
pageScrollStart();
console.log('dolu start');
act = 1;
}
}
});
function pageScrollStart() {
window.scrollBy(0,1);
scrolldelay = setTimeout('pageScrollStart()',50);
};
function pageScrollStop(){
clearTimeout(scrolldelay);
}
</script>