Advertisement
Guest User

Untitled

a guest
Jul 26th, 2016
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. // requires raf.js (polyfil)
  2.  
  3. (function(){
  4. var ids = {};
  5.  
  6. function requestId(){
  7. var id;
  8. while (!id || ids.hasOwnProperty(id)){
  9. id = Math.floor(Math.random() * 1E9);
  10. };
  11. return id;
  12. }
  13.  
  14. if (!window.requestNextAnimationFrame) {
  15. window.requestNextAnimationFrame = function(callback, element) {
  16. var id = requestId();
  17.  
  18. ids[id] = requestAnimationFrame(function(){
  19. ids[id] = requestAnimationFrame(function(ts){
  20. delete ids[id];
  21. callback(ts);
  22. },element);
  23. },element);
  24.  
  25. return id;
  26. };
  27. }
  28.  
  29. if (!window.cancelNextAnimationFrame) {
  30. window.cancelNextAnimationFrame = function(id) {
  31. if (ids[id]) {
  32. cancelAnimationFrame(ids[id]);
  33. delete ids[id];
  34. }
  35. };
  36. }
  37. })();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement