File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed
Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change 1+ // http://paulirish.com/2011/requestanimationframe-for-smart-animating/
2+ // http://my.opera.com/emoller/blog/2011/12/20/requestanimationframe-for-smart-er-animating
3+ // https://gist.github.com/paulirish/1579671
4+ // requestAnimationFrame polyfill by Erik Möller. fixes from Paul Irish and Tino Zijdel
5+
6+ // MIT license
7+
8+ ( function ( ) {
9+ var lastTime = 0 ;
10+ var vendors = [ 'ms' , 'moz' , 'webkit' , 'o' ] ;
11+ for ( var x = 0 ; x < vendors . length && ! window . requestAnimationFrame ; ++ x ) {
12+ window . requestAnimationFrame = window [ vendors [ x ] + 'RequestAnimationFrame' ] ;
13+ window . cancelAnimationFrame = window [ vendors [ x ] + 'CancelAnimationFrame' ]
14+ || window [ vendors [ x ] + 'CancelRequestAnimationFrame' ] ;
15+ }
16+
17+ if ( ! window . requestAnimationFrame )
18+ window . requestAnimationFrame = function ( callback , element ) {
19+ var currTime = new Date ( ) . getTime ( ) ;
20+ var timeToCall = Math . max ( 0 , 16 - ( currTime - lastTime ) ) ;
21+ var id = window . setTimeout ( function ( ) { callback ( currTime + timeToCall ) ; } ,
22+ timeToCall ) ;
23+ lastTime = currTime + timeToCall ;
24+ return id ;
25+ } ;
26+
27+ if ( ! window . cancelAnimationFrame )
28+ window . cancelAnimationFrame = function ( id ) {
29+ clearTimeout ( id ) ;
30+ } ;
31+ } ( ) ) ;
You can’t perform that action at this time.
0 commit comments