jQuery plugin for requestAnimationFrame based event throttling
bower install jquery-throttle
<script src="bower_components/requestAnimationFrame.js/requestAnimationFrame.js"></script>
<script src="bower_components/jquery-throttle/jquery.throttle.js"></script>
Use in the same way as you would use jQuery's .on() and .off():
$(window).throttle("resize", function() {
// your code here
});
$(window).removeThrottle("resize");
If you're developing a plugin, check if jquery.throttle is available, and fallback to jQuery.on().
if (typeof($(window).throttle) == "function") {
$(window).throttle("resize", function() {
// your code here
});
}
else {
$(window).on("resize", onResize);
}