chuanxshi / javascript-patterns

JavaScript Design Patterns

Home Page:http://shichuan.github.io/javascript-patterns

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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);
});