Skip to content

Instantly share code, notes, and snippets.

@jtangelder
Last active December 21, 2015 22:38
Show Gist options
  • Select an option

  • Save jtangelder/6376325 to your computer and use it in GitHub Desktop.

Select an option

Save jtangelder/6376325 to your computer and use it in GitHub Desktop.

Revisions

  1. jtangelder revised this gist May 1, 2014. 2 changed files with 24 additions and 1 deletion.
    24 changes: 24 additions & 0 deletions jquery.raf.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,24 @@
    (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);
    1 change: 0 additions & 1 deletion jquery.raf.min.js
    Original file line number Diff line number Diff line change
    @@ -1 +0,0 @@
    !function(a,b){var c,d,e;d=Modernizr.prefixed("requestAnimationFrame",a),d&&(c=!1,e=function(){c&&(d(e),b.fx.tick())},b.fx.timer=function(a){a()&&b.timers.push(a)&&!c&&(c=!0,e())},b.fx.stop=function(){c=!1})}(window,jQuery);
  2. jtangelder revised this gist Aug 29, 2013. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion jquery.raf.min.js
    Original file line number Diff line number Diff line change
    @@ -1 +1 @@
    !function(a,b){var c,d,e;return(d=Modernizr.prefixed("requestAnimationFrame",a))?(c=!1,e=function(){return c?(d(e),b.fx.tick()):void 0},b.fx.timer=function(a){return a()&&b.timers.push(a)&&!c?(c=!0,e()):void 0},b.fx.stop=function(){return c=!1}):void 0}(window,jQuery);
    !function(a,b){var c,d,e;d=Modernizr.prefixed("requestAnimationFrame",a),d&&(c=!1,e=function(){c&&(d(e),b.fx.tick())},b.fx.timer=function(a){a()&&b.timers.push(a)&&!c&&(c=!0,e())},b.fx.stop=function(){c=!1})}(window,jQuery);
  3. jtangelder revised this gist Aug 29, 2013. 1 changed file with 1 addition and 0 deletions.
    1 change: 1 addition & 0 deletions jquery.raf.min.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1 @@
    !function(a,b){var c,d,e;return(d=Modernizr.prefixed("requestAnimationFrame",a))?(c=!1,e=function(){return c?(d(e),b.fx.tick()):void 0},b.fx.timer=function(a){return a()&&b.timers.push(a)&&!c?(c=!0,e()):void 0},b.fx.stop=function(){return c=!1}):void 0}(window,jQuery);
  4. jtangelder revised this gist Aug 29, 2013. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions jquery.raf.coffee
    Original file line number Diff line number Diff line change
    @@ -3,13 +3,11 @@
    # use Modernizr to get the (prefixed)DOM method
    raf = Modernizr.prefixed('requestAnimationFrame', win)

    # just use jquery animate when no raf is available
    if not raf
    return

    animating = false;

    # request frame
    tick = ()->
    if animating
    raf(tick)
  5. jtangelder created this gist Aug 29, 2013.
    25 changes: 25 additions & 0 deletions jquery.raf.coffee
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,25 @@
    # hack jQuery to use requestAnimationFrame for animations
    ((win, $)->
    # use Modernizr to get the (prefixed)DOM method
    raf = Modernizr.prefixed('requestAnimationFrame', win)

    # just use jquery animate when no raf is available
    if not raf
    return

    animating = false;

    # request frame
    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)