Animations now use a single interval timer, global for all animations. This severely improves the performance and responsiveness of the animations in most browsers.
This commit is contained in:
parent
83b43a1e92
commit
1d0dec55ba
1 changed files with 20 additions and 7 deletions
27
src/fx/fx.js
27
src/fx/fx.js
|
@ -400,6 +400,8 @@ jQuery.extend({
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
timers: [],
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* I originally wrote fx() as a clone of moo.fx and in the process
|
* I originally wrote fx() as a clone of moo.fx and in the process
|
||||||
* of making it small in size the code became illegible to sane
|
* of making it small in size the code became illegible to sane
|
||||||
|
@ -452,9 +454,20 @@ jQuery.extend({
|
||||||
z.now = from;
|
z.now = from;
|
||||||
z.a();
|
z.a();
|
||||||
|
|
||||||
z.timer = setInterval(function(){
|
jQuery.timers.push(function(){
|
||||||
z.step(from, to);
|
return z.step(from, to);
|
||||||
}, 13);
|
});
|
||||||
|
|
||||||
|
if ( jQuery.timers.length == 1 ) {
|
||||||
|
var timer = setInterval(function(){
|
||||||
|
jQuery.timers = jQuery.grep( jQuery.timers, function(fn){
|
||||||
|
return fn();
|
||||||
|
});
|
||||||
|
|
||||||
|
if ( !jQuery.timers.length )
|
||||||
|
clearInterval( timer );
|
||||||
|
}, 13);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// Simple 'show' function
|
// Simple 'show' function
|
||||||
|
@ -516,10 +529,6 @@ jQuery.extend({
|
||||||
var t = (new Date()).getTime();
|
var t = (new Date()).getTime();
|
||||||
|
|
||||||
if (t > options.duration + z.startTime) {
|
if (t > options.duration + z.startTime) {
|
||||||
// Stop the timer
|
|
||||||
clearInterval(z.timer);
|
|
||||||
z.timer = null;
|
|
||||||
|
|
||||||
z.now = lastNum;
|
z.now = lastNum;
|
||||||
z.a();
|
z.a();
|
||||||
|
|
||||||
|
@ -555,6 +564,8 @@ jQuery.extend({
|
||||||
if ( done && jQuery.isFunction( options.complete ) )
|
if ( done && jQuery.isFunction( options.complete ) )
|
||||||
// Execute the complete function
|
// Execute the complete function
|
||||||
options.complete.apply( elem );
|
options.complete.apply( elem );
|
||||||
|
|
||||||
|
return false;
|
||||||
} else {
|
} else {
|
||||||
var n = t - this.startTime;
|
var n = t - this.startTime;
|
||||||
// Figure out where in the animation we are and set the number
|
// Figure out where in the animation we are and set the number
|
||||||
|
@ -569,6 +580,8 @@ jQuery.extend({
|
||||||
// Perform the next step of the animation
|
// Perform the next step of the animation
|
||||||
z.a();
|
z.a();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue