diff --git a/index.html b/index.html index 978f7f973fbf28124fc1e9d254efcaf5e036c961..bbb4f6051d3695876d4be757a0bacf8d93345616 100644 --- a/index.html +++ b/index.html @@ -78,6 +78,7 @@ + diff --git a/js/animframe_polyfill.js b/js/animframe_polyfill.js new file mode 100644 index 0000000000000000000000000000000000000000..c45a13e204478ffd468beebcb10bb143a283b34b --- /dev/null +++ b/js/animframe_polyfill.js @@ -0,0 +1,26 @@ +(function() { + var lastTime = 0; + var vendors = ['webkit', 'moz']; + for(var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) { + window.requestAnimationFrame = window[vendors[x]+'RequestAnimationFrame']; + window.cancelAnimationFrame = + window[vendors[x]+'CancelAnimationFrame'] || window[vendors[x]+'CancelRequestAnimationFrame']; + } + + if (!window.requestAnimationFrame) { + window.requestAnimationFrame = function(callback, element) { + 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; + }; + } + + if (!window.cancelAnimationFrame) { + window.cancelAnimationFrame = function(id) { + clearTimeout(id); + }; + } +}());