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:
timmywil 2011-04-04 19:25:12 -04:00
parent 5b0369366a
commit fe3203bb5b
2 changed files with 13 additions and 17 deletions

16
src/effects.js vendored
View file

@ -11,7 +11,8 @@ var elemdisplay = {},
[ "width", "marginLeft", "marginRight", "paddingLeft", "paddingRight" ], [ "width", "marginLeft", "marginRight", "paddingLeft", "paddingRight" ],
// opacity animations // opacity animations
[ "opacity" ] [ "opacity" ]
]; ],
requestAnimationFrame = window.webkitRequestAnimationFrame || window.mozRequestionAnimationFrame;
jQuery.fn.extend({ jQuery.fn.extend({
show: function( speed, easing, callback ) { show: function( speed, easing, callback ) {
@ -364,16 +365,19 @@ jQuery.fx.prototype = {
if ( t() && jQuery.timers.push(t) && !timerId ) { if ( t() && jQuery.timers.push(t) && !timerId ) {
// Use requestAnimationFrame instead of setInterval if available // Use requestAnimationFrame instead of setInterval if available
( timerId = jQuery.support.requestAnimationFrame ) ? if ( requestAnimationFrame ) {
window[timerId](function raf() { timerId = 1;
// timerId will be true as long as the animation hasn't been stopped requestAnimationFrame(function raf() {
// When timerId gets set to null at any point, this stops
if ( timerId ) { if ( timerId ) {
window[timerId](raf); requestAnimationFrame( raf );
fx.tick(); fx.tick();
} }
}): });
} else {
timerId = setInterval( fx.tick, fx.interval ); timerId = setInterval( fx.tick, fx.interval );
} }
}
}, },
// Simple 'show' function // Simple 'show' function

View file

@ -13,8 +13,7 @@
a = div.getElementsByTagName("a")[0], a = div.getElementsByTagName("a")[0],
select = document.createElement("select"), select = document.createElement("select"),
opt = select.appendChild( document.createElement("option") ), opt = select.appendChild( document.createElement("option") ),
input = div.getElementsByTagName("input")[0], input = div.getElementsByTagName("input")[0];
raf = "RequestAnimationFrame";
// Can't get basic test support // Can't get basic test support
if ( !all || !all.length || !a ) { if ( !all || !all.length || !a ) {
@ -59,13 +58,6 @@
// (WebKit defaults to false instead of true, IE too, if it's in an optgroup) // (WebKit defaults to false instead of true, IE too, if it's in an optgroup)
optSelected: opt.selected, optSelected: opt.selected,
// Verify requestAnimationFrame mechanism existence
// use the prefixed name as the value
requestAnimationFrame:
window['moz' + raf] ? 'moz' + raf :
window['webkit' + raf] ? 'webkit' + raf :
false,
// Will be defined later // Will be defined later
deleteExpando: true, deleteExpando: true,
optDisabled: false, optDisabled: false,