jquery-patterns / window-scroll-event.html
rusteater opened this issue · comments
The whole point of not doing much in the scroll event handler is because it degrades performance, but there's no reason to have a constant timer running. You should be running it only when the user starts scrolling:
var scrollTimer;
$(window).scroll(function() {
scrollTimer && clearTimeout(scrollTimer);
scrollTimer = setTimeout(function() {
// Check your page position and then
// Load in more results
// Whatever else...
}, 250);
});
this is fixed in preferred method 2 https://github.com/shichuan/javascript-patterns/blob/master/jquery-patterns/window-scroll-event.html#L36-53