Last active
December 21, 2015 22:38
-
-
Save jtangelder/6376325 to your computer and use it in GitHub Desktop.
hack jQuery to use requestAnimationFrame for animations
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
# hack jQuery to use requestAnimationFrame for animations | |
((win, $)-> | |
# use Modernizr to get the (prefixed)DOM method | |
raf = Modernizr.prefixed('requestAnimationFrame', win) | |
if not raf | |
return | |
animating = false; | |
tick = ()-> | |
if animating | |
raf(tick) | |
$.fx.tick() | |
$.fx.timer = (timer)-> | |
if timer() and $.timers.push(timer) and !animating | |
animating = true | |
tick() | |
$.fx.stop = ()-> | |
animating = false | |
)(window, jQuery) |
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
(function(win, $) { | |
var animating, raf, tick; | |
raf = Modernizr.prefixed('requestAnimationFrame', win); | |
if (!raf) { | |
return; | |
} | |
animating = false; | |
function tick() { | |
if (animating) { | |
raf(tick); | |
$.fx.tick(); | |
} | |
}; | |
$.fx.timer = function(timer) { | |
if (timer() && $.timers.push(timer) && !animating) { | |
animating = true; | |
tick(); | |
} | |
}; | |
$.fx.stop = function() { | |
animating = false; | |
}; | |
})(window, jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment