Skip to content

Instantly share code, notes, and snippets.

@danyeah
Last active August 29, 2015 14:13
Show Gist options
  • Select an option

  • Save danyeah/ab2f6ec2d5b8b3d93955 to your computer and use it in GitHub Desktop.

Select an option

Save danyeah/ab2f6ec2d5b8b3d93955 to your computer and use it in GitHub Desktop.
Animation Frame with polyfill
window.animFrame = (function(){
return window.requestAnimationFrame||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
function( callback ){
window.setTimeout(callback, 15);
};
})();
var scrollTimeout;
$(window).scroll(function () {
if (scrollTimeout) {
// clear the timeout, if one is pending
clearTimeout(scrollTimeout);
scrollTimeout = null;
}
scrollTimeout = animFrame(myFunc, 150);
});
function myFunc() {
//your code
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment