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.
This commit is contained in:
parent
5b0369366a
commit
fe3203bb5b
2 changed files with 13 additions and 17 deletions
20
src/effects.js
vendored
20
src/effects.js
vendored
|
@ -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 );
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue