Skip to content

Instantly share code, notes, and snippets.

@jtangelder
Last active December 21, 2015 22:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jtangelder/6376325 to your computer and use it in GitHub Desktop.
Save jtangelder/6376325 to your computer and use it in GitHub Desktop.
hack jQuery to use requestAnimationFrame for animations
# 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)
(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