Last active
August 29, 2015 14:13
-
-
Save danyeah/ab2f6ec2d5b8b3d93955 to your computer and use it in GitHub Desktop.
Animation Frame with polyfill
This file contains hidden or 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
| 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