summaryrefslogtreecommitdiffstats
path: root/request-animation-frame.js
diff options
context:
space:
mode:
authorDavid DeSandro <desandrocodes@gmail.com>2014-12-21 12:20:54 -0500
committerDavid DeSandro <desandrocodes@gmail.com>2014-12-21 12:20:54 -0500
commita3ff3a4a0684f77e7f3be9d0223aedd551cbeec4 (patch)
treee70f1d57be67b6a135538f2744ae660669dba2eb /request-animation-frame.js
parent9e326512d2fb3f6b1821d2ce9ad8a62b82c475ef (diff)
downloadflickity-dev-a3ff3a4a0684f77e7f3be9d0223aedd551cbeec4.zip
flickity-dev-a3ff3a4a0684f77e7f3be9d0223aedd551cbeec4.tar.gz
flickity-dev-a3ff3a4a0684f77e7f3be9d0223aedd551cbeec4.tar.bz2
remove sandbox/
Diffstat (limited to 'request-animation-frame.js')
-rw-r--r--request-animation-frame.js37
1 files changed, 37 insertions, 0 deletions
diff --git a/request-animation-frame.js b/request-animation-frame.js
new file mode 100644
index 0000000..661e15d
--- /dev/null
+++ b/request-animation-frame.js
@@ -0,0 +1,37 @@
+// -------------------------- requestAnimationFrame -------------------------- //
+
+// https://gist.github.com/1866474
+
+var lastTime = 0;
+var prefixes = 'webkit moz ms o'.split(' ');
+// get unprefixed rAF and cAF, if present
+var rAF = window.requestAnimationFrame;
+var cAF = window.cancelAnimationFrame;
+// loop through vendor prefixes and get prefixed rAF and cAF
+var prefix;
+for( var i = 0; i < prefixes.length; i++ ) {
+ if ( rAF && cAF ) {
+ break;
+ }
+ prefix = prefixes[i];
+ rAF = rAF || window[ prefix + 'RequestAnimationFrame' ];
+ cAF = cAF || window[ prefix + 'CancelAnimationFrame' ] ||
+ window[ prefix + 'CancelRequestAnimationFrame' ];
+}
+
+// fallback to setTimeout and clearTimeout if either request/cancel is not supported
+if ( !rAF || !cAF ) {
+ rAF = function( callback ) {
+ var currTime = new Date().getTime();
+ var timeToCall = Math.max( 0, 16 - ( currTime - lastTime ) );
+ var id = window.setTimeout( function() {
+ callback( currTime + timeToCall );
+ }, timeToCall );
+ lastTime = currTime + timeToCall;
+ return id;
+ };
+
+ cAF = function( id ) {
+ window.clearTimeout( id );
+ };
+} \ No newline at end of file