aboutsummaryrefslogtreecommitdiffstats
path: root/src/effects.js
diff options
context:
space:
mode:
authorjaubourg <j@ubourg.net>2011-04-11 13:41:17 +0200
committerjaubourg <j@ubourg.net>2011-04-11 13:41:17 +0200
commit4c3aba9a15c936696ad2e799f7e372bf2aeb38a5 (patch)
treebe25f30c1eb60aa2b87412b51eab7745b2005760 /src/effects.js
parent3411d47a6a952e283864d2401438a6764d925b74 (diff)
parent56ffad2dad138293c132e6ad353111bd2d1f1239 (diff)
downloadjquery-4c3aba9a15c936696ad2e799f7e372bf2aeb38a5.tar.gz
jquery-4c3aba9a15c936696ad2e799f7e372bf2aeb38a5.zip
Merge branch 'master' of github.com:jquery/jquery
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 d6eff7b32..7aec83009 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;
@@ -368,7 +371,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;
@@ -384,7 +388,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 );
+ }
}
},