23
23
// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
24
24
25
25
26
- var animating ,
27
- lastTime = 0 ,
28
- vendors = [ 'webkit' , 'moz' ] ,
29
- requestAnimationFrame = window . requestAnimationFrame ,
30
- cancelAnimationFrame = window . cancelAnimationFrame ;
31
-
32
- for ( ; lastTime < vendors . length && ! requestAnimationFrame ; lastTime ++ ) {
33
- requestAnimationFrame = window [ vendors [ lastTime ] + "RequestAnimationFrame" ] ;
34
- cancelAnimationFrame = cancelAnimationFrame ||
35
- window [ vendors [ lastTime ] + "CancelAnimationFrame" ] ||
36
- window [ vendors [ lastTime ] + "CancelRequestAnimationFrame" ] ;
37
- }
26
+ var animating ;
38
27
39
28
function raf ( ) {
40
29
if ( animating ) {
41
- requestAnimationFrame ( raf ) ;
30
+ window . requestAnimationFrame ( raf ) ;
42
31
jQuery . fx . tick ( ) ;
43
32
}
44
33
}
45
34
46
- if ( requestAnimationFrame ) {
47
- // use rAF
48
- window . requestAnimationFrame = requestAnimationFrame ;
49
- window . cancelAnimationFrame = cancelAnimationFrame ;
35
+ if ( window . requestAnimationFrame ) {
50
36
jQuery . fx . timer = function ( timer ) {
51
37
if ( timer ( ) && jQuery . timers . push ( timer ) && ! animating ) {
52
38
animating = true ;
@@ -57,22 +43,6 @@ if ( requestAnimationFrame ) {
57
43
jQuery . fx . stop = function ( ) {
58
44
animating = false ;
59
45
} ;
60
- } else {
61
- // polyfill
62
- window . requestAnimationFrame = function ( callback , element ) {
63
- var currTime = new Date ( ) . getTime ( ) ,
64
- timeToCall = Math . max ( 0 , 16 - ( currTime - lastTime ) ) ,
65
- id = window . setTimeout ( function ( ) {
66
- callback ( currTime + timeToCall ) ;
67
- } , timeToCall ) ;
68
- lastTime = currTime + timeToCall ;
69
- return id ;
70
- } ;
71
-
72
- window . cancelAnimationFrame = function ( id ) {
73
- clearTimeout ( id ) ;
74
- } ;
75
-
76
46
}
77
47
78
48
} ) ) ;
0 commit comments