Source: Core/cancelAnimationFrame.js

  1. /*global define*/
  2. define([
  3. './defined'
  4. ], function(
  5. defined) {
  6. 'use strict';
  7. if (typeof window === 'undefined') {
  8. return;
  9. }
  10. var implementation = window.cancelAnimationFrame;
  11. (function() {
  12. // look for vendor prefixed function
  13. if (!defined(implementation)) {
  14. var vendors = ['webkit', 'moz', 'ms', 'o'];
  15. var i = 0;
  16. var len = vendors.length;
  17. while (i < len && !defined(implementation)) {
  18. implementation = window[vendors[i] + 'CancelAnimationFrame'];
  19. if (!defined(implementation)) {
  20. implementation = window[vendors[i] + 'CancelRequestAnimationFrame'];
  21. }
  22. ++i;
  23. }
  24. }
  25. // otherwise, assume requestAnimationFrame is based on setTimeout, so use clearTimeout
  26. if (!defined(implementation)) {
  27. implementation = clearTimeout;
  28. }
  29. })();
  30. /**
  31. * A browser-independent function to cancel an animation frame requested using {@link requestAnimationFrame}.
  32. *
  33. * @exports cancelAnimationFrame
  34. *
  35. * @param {Number} requestID The value returned by {@link requestAnimationFrame}.
  36. *
  37. * @see {@link http://www.w3.org/TR/animation-timing/#the-WindowAnimationTiming-interface|The WindowAnimationTiming interface}
  38. */
  39. function cancelAnimationFrame(requestID) {
  40. // we need this extra wrapper function because the native cancelAnimationFrame
  41. // functions must be invoked on the global scope (window), which is not the case
  42. // if invoked as Cesium.cancelAnimationFrame(requestID)
  43. implementation(requestID);
  44. }
  45. return cancelAnimationFrame;
  46. });