source: other-projects/nz-flag-design/trunk/design-2d/Original editor.method.ac/editor/lib/requestanimationframe.js@ 29468

Last change on this file since 29468 was 29468, checked in by sjs49, 9 years ago

Initial commit for editor.method.ac for flag design

  • Property svn:executable set to *
File size: 961 bytes
Line 
1(function() {
2 var lastTime = 0;
3 var vendors = ['ms', 'moz', 'webkit', 'o'];
4 for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
5 window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame'];
6 window.cancelAnimationFrame =
7 window[vendors[x]+'CancelAnimationFrame'] || window[vendors[x]+'CancelRequestAnimationFrame'];
8 }
9
10 if (!window.requestAnimationFrame)
11 window.requestAnimationFrame = function(callback, element) {
12 var currTime = new Date().getTime();
13 var timeToCall = Math.max(0, 16 - (currTime - lastTime));
14 var id = window.setTimeout(function() { callback(currTime + timeToCall); },
15 timeToCall);
16 lastTime = currTime + timeToCall;
17 return id;
18 };
19
20 if (!window.cancelAnimationFrame)
21 window.cancelAnimationFrame = function(id) {
22 clearTimeout(id);
23 };
24}());
Note: See TracBrowser for help on using the repository browser.