使用鼠标滚轮插件,我有:
$('html, body').bind("mousewheel", function(objEvent, intDelta){
if (intDelta > 0 && $currentPage != 1){
$currentPage--;
$('html, body').animate({scrollTop:$("#page"+$currentPage).offset().top}, 2000);
}
else if (intDelta < 0 && $currentPage != 4){
$currentPage++;
$('html, body').animate({scrollTop:$("#page"+$currentPage).offset().top}, 2000);
}
});
效果很好,但是每当我滚动时,它都会在执行动画之前先向上或向下滚动页面一个刻度。有什么办法可以禁用这个吗?谢谢!
最佳答案
只需添加一个
return false;
最后一个大括号之前。
$('html, body').bind("mousewheel", function(objEvent, intDelta){
if (intDelta > 0 && $currentPage != 1){
$currentPage--;
$('html, body').animate({scrollTop:$("#page"+$currentPage).offset().top}, 2000);
}
else if (intDelta < 0 && $currentPage != 4){
$currentPage++;
$('html, body').animate({scrollTop:$("#page"+$currentPage).offset().top}, 2000);
}
return false;
});
顺便说一句,你应该使用 .on() 而不是 .bind()
关于jquery - 禁用 jQuery 中的正常滚轮功能?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10048243/