Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // requires raf.js (polyfil)
- (function(){
- var ids = {};
- function requestId(){
- var id;
- while (!id || ids.hasOwnProperty(id)){
- id = Math.floor(Math.random() * 1E9);
- };
- return id;
- }
- if (!window.requestNextAnimationFrame) {
- window.requestNextAnimationFrame = function(callback, element) {
- var id = requestId();
- ids[id] = requestAnimationFrame(function(){
- ids[id] = requestAnimationFrame(function(ts){
- delete ids[id];
- callback(ts);
- },element);
- },element);
- return id;
- };
- }
- if (!window.cancelNextAnimationFrame) {
- window.cancelNextAnimationFrame = function(id) {
- if (ids[id]) {
- cancelAnimationFrame(ids[id]);
- delete ids[id];
- }
- };
- }
- })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement