diff options
author | timmywil <tim.willison@thisismedium.com> | 2011-04-04 19:25:12 -0400 |
---|---|---|
committer | timmywil <tim.willison@thisismedium.com> | 2011-04-04 19:25:12 -0400 |
commit | fe3203bb5bdc0049467214e7f0979a3487d5681b (patch) | |
tree | 77fa7f41c85b682a945ff5cc9e5df4a7805ec506 /src/effects.js | |
parent | 5b0369366a83d7339f925bfef3a277d7287c9bd2 (diff) | |
download | jquery-fe3203bb5bdc0049467214e7f0979a3487d5681b.tar.gz jquery-fe3203bb5bdc0049467214e7f0979a3487d5681b.zip |
Some adjustments and style edits on lrbabe's pull for requestAnimationFrame
- Moved support.js check to effects.js. This is just an assignment to the function if it exists. Removed string concatenations.
+ Still need to do the checks on window, but after that, window is no longer needed.
- Switched ternary to an if statmenet
- assigned timerId to a number rather than the function. I did perf tests to check which is faster.
Diffstat (limited to 'src/effects.js')
-rw-r--r-- | src/effects.js | 20 |
1 files changed, 12 insertions, 8 deletions
diff --git a/src/effects.js b/src/effects.js index e5a10295c..9835e9598 100644 --- a/src/effects.js +++ b/src/effects.js @@ -11,7 +11,8 @@ var elemdisplay = {}, [ "width", "marginLeft", "marginRight", "paddingLeft", "paddingRight" ], // opacity animations [ "opacity" ] - ]; + ], + requestAnimationFrame = window.webkitRequestAnimationFrame || window.mozRequestionAnimationFrame; jQuery.fn.extend({ show: function( speed, easing, callback ) { @@ -364,15 +365,18 @@ jQuery.fx.prototype = { if ( t() && jQuery.timers.push(t) && !timerId ) { // Use requestAnimationFrame instead of setInterval if available - ( timerId = jQuery.support.requestAnimationFrame ) ? - window[timerId](function raf() { - // timerId will be true as long as the animation hasn't been stopped - if (timerId) { - window[timerId](raf); + if ( requestAnimationFrame ) { + timerId = 1; + requestAnimationFrame(function raf() { + // When timerId gets set to null at any point, this stops + if ( timerId ) { + requestAnimationFrame( raf ); fx.tick(); } - }): - timerId = setInterval(fx.tick, fx.interval); + }); + } else { + timerId = setInterval( fx.tick, fx.interval ); + } } }, |