Created
November 8, 2016 04:47
-
-
Save patrinhani-ciandt/a2fbc165dcb5719d800c72fd2fcbb031 to your computer and use it in GitHub Desktop.
Request animation replacer to use when browser tab is unselected and you need to avoid to page load waiting to tab get focus
This file contains 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 characters
(function(root) { | |
var originalRAF = root.requestAnimationFrame; | |
var customRAF = function (cb) { | |
return setTimeout(cb, 1000 / 60); | |
}; | |
var useOriginal = false; | |
//overwrite the function only once because other components also overwrite it | |
//this way, no one will have directly reference to customRAF | |
root.requestAnimationFrame = function(cb) { | |
return useOriginal ? originalRAF(cb) : customRAF(cb); | |
}; | |
originalRAF(function() { | |
useOriginal = true; //will be executed when page get focus | |
}); | |
})(window); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment