jQuery-如何将滚动视为单个事件? [英] jQuery - how to treat scroll as single event?
本文介绍了jQuery-如何将滚动视为单个事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
当我将功能绑定到滚动和滚动鼠标滚轮一次时,该功能将运行七或八次.我希望它在滚动鼠标滚轮一次时仅运行一次,这可能吗?我使用以下代码:
When I bind function to scroll and scroll mousewheel once, the function runs seven or eight times. I want it to run only once when I scroll the mousewheel once, is this possible? I use this code:
$(document).ready(function () {
$(window).bind('scroll', function() {
alert("Scroll.");
}
});
});
推荐答案
尝试
$(document).ready(function () {
var timerId;
$(window).bind('scroll', function() {
clearTimeout(timerId)
timerId = setTimeout(function(){
alert("Scroll.");
}, 200)
});
});
演示:小提琴
这篇关于jQuery-如何将滚动视为单个事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文