Last active
March 27, 2022 03:02
-
-
Save iangilman/5824967 to your computer and use it in GitHub Desktop.
Revisions
-
iangilman revised this gist
Oct 23, 2015 . No changes.There are no files selected for viewing
-
iangilman revised this gist
Jun 20, 2013 . 1 changed file with 1 addition and 1 deletion.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,5 +1,5 @@ // Modified from http://mattsnider.com/cross-browser-and-legacy-supported-requestframeanimation/ // LICENSE: MIT: http://mattsnider.com/projects/license/ (function(w) { "use strict"; -
iangilman revised this gist
Jun 20, 2013 . 1 changed file with 3 additions and 0 deletions.There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -1,3 +1,6 @@ // Modified from http://mattsnider.com/cross-browser-and-legacy-supported-requestframeanimation/ // LICENSE: http://mattsnider.com/projects/license/ (function(w) { "use strict"; // most browsers have an implementation -
iangilman created this gist
Jun 20, 2013 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,70 @@ (function(w) { "use strict"; // most browsers have an implementation w.requestAnimationFrame = w.requestAnimationFrame || w.mozRequestAnimationFrame || w.webkitRequestAnimationFrame || w.msRequestAnimationFrame; w.cancelAnimationFrame = w.cancelAnimationFrame || w.mozCancelAnimationFrame || w.webkitCancelAnimationFrame || w.msCancelAnimationFrame; // polyfill, when necessary if (!w.requestAnimationFrame) { var aAnimQueue = [], aProcessing = [], iRequestId = 0, iIntervalId; // create a mock requestAnimationFrame function w.requestAnimationFrame = function(callback) { aAnimQueue.push([++iRequestId, callback]); if (!iIntervalId) { iIntervalId = setInterval(function() { if (aAnimQueue.length) { var time = +new Date(); // Process all of the currently outstanding frame // requests, but none that get added during the // processing. // Swap the arrays so we don't have to create a new // array every frame. var temp = aProcessing; aProcessing = aAnimQueue; aAnimQueue = temp; while (aProcessing.length) { aProcessing.shift()[1](time); } } else { // don't continue the interval, if unnecessary clearInterval(iIntervalId); iIntervalId = undefined; } }, 1000 / 50); // estimating support for 50 frames per second } return iRequestId; }; // create a mock cancelAnimationFrame function w.cancelAnimationFrame = function(requestId) { // find the request ID and remove it var i, j; for (i = 0, j = aAnimQueue.length; i < j; i += 1) { if (aAnimQueue[i][0] === requestId) { aAnimQueue.splice(i, 1); return; } } // If it's not in the queue, it may be in the set we're currently // processing (if cancelAnimationFrame is called from within a // requestAnimationFrame callback). for (i = 0, j = aProcessing.length; i < j; i += 1) { if (aProcessing[i][0] === requestId) { aProcessing.splice(i, 1); return; } } }; } })(window);