I am using the following code to call a function when the screen is less than 200 but I can't disable the function when the scroll is more than 200.
我在屏幕小于200时使用以下代码调用函数但是当滚动超过200时我无法禁用该函数。
function animateHeader() {
$(selector)
.animate({ opacity: 0.0, bottom: 70 }, { duration: 600 })
.animate({ opacity: 0.0, bottom: 50 }, { duration: 0 })
.animate({ opacity: 0.0, bottom: 70 }, { duration: 600, complete: animateHeader })
}
$window.on('scroll', function() {
if ($(window).scrollTop() < 200) {
animateHeader();
} else {
// Disable animateHeader()
}
}); // Finish scroll
I know there are alternatives to not call a function here in this case, but is it possible to disable a function when it's already active?
我知道在这种情况下有一些替代方法可以不调用函数,但是当它已经处于活动状态时是否可以禁用它?
1 个解决方案
#1
Try using stop()
function:
尝试使用stop()函数:
else {
$(selector).stop();
}
#1
Try using stop()
function:
尝试使用stop()函数:
else {
$(selector).stop();
}