Last active
July 5, 2016 06:34
-
-
Save Samjin/aea494432e09eabdb839 to your computer and use it in GitHub Desktop.
Scroll() event optimization
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var throttle = (function () { | |
return function (fn, delay) { | |
delay || (delay = 100); | |
var last = +new Date; | |
return function () { | |
var now = +new Date; | |
if (now - last > delay) { | |
fn.apply(this, arguments); | |
last = now; | |
} | |
}; | |
}; | |
})(); | |
And then it can be used like this: | |
var outerPane = $details.find(".details-pane-outer"), | |
$(window).scroll(throttle(function() { | |
// Check your page position and then | |
// Load in more results | |
}, 250)); | |
https://github.com/shichuan/javascript-patterns/blob/master/jquery-patterns/window-scroll-event.html |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment