jquery - 禁用 jQuery 中的正常滚轮功能?

标签 jquery

使用鼠标滚轮插件,我有:

$('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/

相关文章:

javascript - 使用 jquery 将值转换为自定义进度条的百分比

javascript - 使用 jQuery UI 模态对话框作为确认

Jquery 淡入淡出不工作

jquery - PDF.js - 在嵌入式 PDF 上使用搜索功能

php - 如何从 prettyPhoto 灯箱中删除滚动条?

javascript - 是否可以在html中阅读pdf?

javascript - 没有可用的数据,两侧中心(垂直 + 水平)与 HTML,CSS

javascript - 从页面源代码中隐藏脚本

javascript - 刷新 OnKeyUp Search Filter 的结果

javascript - 如何在不迷失方向的情况下移动旋转 Canvas 图像?