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.");
}
});
});
Try
$(document).ready(function () {
var timerId;
$(window).bind('scroll', function() {
clearTimeout(timerId)
timerId = setTimeout(function(){
alert("Scroll.");
}, 200)
});
});
Demo: Fiddle
You can use throttle function from jQuery throttle debounce plugin.
$(function() {
$(window).bind('scroll', $.throttle(100, function() {
console.log('scroll');
}));
});
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With