aboutsummaryrefslogtreecommitdiffstats
path: root/src/effects.js
diff options
context:
space:
mode:
authorjeresig <jeresig@gmail.com>2011-04-10 17:27:34 -0400
committerjeresig <jeresig@gmail.com>2011-04-10 17:27:34 -0400
commit56ffad2dad138293c132e6ad353111bd2d1f1239 (patch)
tree027f334992994e68ba4fabf596e84ff06748deb2 /src/effects.js
parent92dfb53314b4654826940eec3dc98aede92d4d49 (diff)
parent791402b4536b8c5cbfeaf27d0a3c639cdb9fd192 (diff)
downloadjquery-56ffad2dad138293c132e6ad353111bd2d1f1239.tar.gz
jquery-56ffad2dad138293c132e6ad353111bd2d1f1239.zip
Merge branch '8101_lrbabe_requestAnimationFrame' of https://github.com/timmywil/jquery into timmywil-8101_lrbabe_requestAnimationFrame
Conflicts: src/effects.js
Diffstat (limited to 'src/effects.js')
-rw-r--r--src/effects.js23
1 files changed, 20 insertions, 3 deletions
diff --git a/src/effects.js b/src/effects.js
index ad2ed3c97..f334ac95b 100644
--- a/src/effects.js
+++ b/src/effects.js
@@ -12,7 +12,10 @@ var elemdisplay = {},
// opacity animations
[ "opacity" ]
],
- fxNow;
+ fxNow,
+ requestAnimationFrame = window.webkitRequestAnimationFrame ||
+ window.mozRequestAnimationFrame ||
+ window.oRequestAnimationFrame;
function clearFxNow() {
fxNow = undefined;
@@ -357,7 +360,8 @@ jQuery.fx.prototype = {
// Start an animation from one number to another
custom: function( from, to, unit ) {
var self = this,
- fx = jQuery.fx;
+ fx = jQuery.fx,
+ raf;
this.startTime = fxNow || createFxNow();
this.start = from;
@@ -373,7 +377,20 @@ jQuery.fx.prototype = {
t.elem = this.elem;
if ( t() && jQuery.timers.push(t) && !timerId ) {
- timerId = setInterval(fx.tick, fx.interval);
+ // Use requestAnimationFrame instead of setInterval if available
+ if ( requestAnimationFrame ) {
+ timerId = 1;
+ raf = function() {
+ // When timerId gets set to null at any point, this stops
+ if ( timerId ) {
+ requestAnimationFrame( raf );
+ fx.tick();
+ }
+ };
+ requestAnimationFrame( raf );
+ } else {
+ timerId = setInterval( fx.tick, fx.interval );
+ }
}
},