如何暂时阻止jquery鼠标滚轮

时间:2013-06-05 09:35:49

标签: jquery

我有一个主页的小动画,需要禁用鼠标滚轮直到它完成(我设法用jquery鼠标滚轮插件)。我的问题是在这个动画之后我无法弄清楚如何再次启用鼠标滚轮。

$('html, body').animate({
scrollTop: $("#header").position().top }, 3000).bind("mousewheel", function() {
return false;     });

1 个答案:

答案 0 :(得分:4)

我猜.unbind("mousewheel")就是这样。所以:

$('html, body').animate({
    scrollTop: $("#header").position().top
}, 3000, function() {
    $(this).unbind("mousewheel");
}).bind("mousewheel", function () {
    return false;
});

.animate() method允许您提供将在动画完成时调用的回调函数,因此在该函数中您可以取消绑定鼠标滚轮处理程序。

(注意:如果您使用jQuery 1.7或更高版本,通常建议使用.on().off()而不是.bind().unbind(),为此他们做同样的事情。)

相关问题