1
- /*! jQuery requestAnimationFrame - v0.1.3pre - 2015-04-27
1
+ /*! jQuery requestAnimationFrame - v0.1.3pre - 2016-02-03
2
2
* https://github.com/gnarf37/jquery-requestAnimationFrame
3
- * Copyright (c) 2015 Corey Frang; Licensed MIT */
3
+ * Copyright (c) 2016 Corey Frang; Licensed MIT */
4
4
5
5
// UMD factory https://github.com/umdjs/umd/blob/master/jqueryPlugin.js
6
6
( function ( factory ) {
7
- if ( typeof define === 'function' && define . amd ) {
7
+ if ( typeof define === 'function' && define . amd ) {
8
8
// AMD. Register as an anonymous module.
9
9
define ( [ 'jquery' ] , factory ) ;
10
- } else {
10
+ } else {
11
11
// Browser globals
12
12
factory ( jQuery ) ;
13
- }
13
+ }
14
14
} ( function ( jQuery ) {
15
15
16
16
// requestAnimationFrame polyfill adapted from Erik Möller
19
19
// http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
20
20
21
21
22
- var animating ,
23
- lastTime = 0 ,
24
- vendors = [ 'webkit' , 'moz' ] ,
25
- requestAnimationFrame = window . requestAnimationFrame ,
26
- cancelAnimationFrame = window . cancelAnimationFrame ;
27
-
28
- for ( ; lastTime < vendors . length && ! requestAnimationFrame ; lastTime ++ ) {
29
- requestAnimationFrame = window [ vendors [ lastTime ] + "RequestAnimationFrame" ] ;
30
- cancelAnimationFrame = cancelAnimationFrame ||
31
- window [ vendors [ lastTime ] + "CancelAnimationFrame" ] ||
32
- window [ vendors [ lastTime ] + "CancelRequestAnimationFrame" ] ;
33
- }
22
+ var animating ;
34
23
35
24
function raf ( ) {
36
25
if ( animating ) {
37
- requestAnimationFrame ( raf ) ;
26
+ window . requestAnimationFrame ( raf ) ;
38
27
jQuery . fx . tick ( ) ;
39
28
}
40
29
}
41
30
42
- if ( requestAnimationFrame ) {
43
- // use rAF
44
- window . requestAnimationFrame = requestAnimationFrame ;
45
- window . cancelAnimationFrame = cancelAnimationFrame ;
31
+ if ( window . requestAnimationFrame ) {
46
32
jQuery . fx . timer = function ( timer ) {
47
33
if ( timer ( ) && jQuery . timers . push ( timer ) && ! animating ) {
48
34
animating = true ;
@@ -53,22 +39,6 @@ if ( requestAnimationFrame ) {
53
39
jQuery . fx . stop = function ( ) {
54
40
animating = false ;
55
41
} ;
56
- } else {
57
- // polyfill
58
- window . requestAnimationFrame = function ( callback , element ) {
59
- var currTime = new Date ( ) . getTime ( ) ,
60
- timeToCall = Math . max ( 0 , 16 - ( currTime - lastTime ) ) ,
61
- id = window . setTimeout ( function ( ) {
62
- callback ( currTime + timeToCall ) ;
63
- } , timeToCall ) ;
64
- lastTime = currTime + timeToCall ;
65
- return id ;
66
- } ;
67
-
68
- window . cancelAnimationFrame = function ( id ) {
69
- clearTimeout ( id ) ;
70
- } ;
71
-
72
42
}
73
43
74
44
} ) ) ;
0 commit comments