我有一个主页的小动画,需要禁用鼠标滚轮直到它完成(我设法用 jquery 鼠标滚轮插件来做到这一点)。我的问题是我无法弄清楚如何在这个动画之后再次启用鼠标滚轮。
$('html, body').animate({
scrollTop: $("#header").position().top }, 3000).bind("mousewheel", function() {
return false; });
我有一个主页的小动画,需要禁用鼠标滚轮直到它完成(我设法用 jquery 鼠标滚轮插件来做到这一点)。我的问题是我无法弄清楚如何在这个动画之后再次启用鼠标滚轮。
$('html, body').animate({
scrollTop: $("#header").position().top }, 3000).bind("mousewheel", function() {
return false; });
我猜.unbind("mousewheel")
会是这样。所以:
$('html, body').animate({
scrollTop: $("#header").position().top
}, 3000, function() {
$(this).unbind("mousewheel");
}).bind("mousewheel", function () {
return false;
});
该.animate()
方法允许您提供将在动画完成时调用的回调函数,因此您可以在该函数中取消绑定鼠标滚轮处理程序。
(注意:如果您使用的是 jQuery 1.7 或更高版本,通常建议使用.on()
and.off()
而不是.bind()
and .unbind()
,尽管为此目的它们做同样的事情。)