cssEvents.js 1023 B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // XXX Should we use something like Moderniz instead of our custom detector?
  2. function whichTransitionEvent() {
  3. const el = document.createElement('fakeelement');
  4. const transitions = {
  5. transition: 'transitionend',
  6. OTransition: 'oTransitionEnd',
  7. MSTransition: 'msTransitionEnd',
  8. MozTransition: 'transitionend',
  9. WebkitTransition: 'webkitTransitionEnd',
  10. };
  11. for (const t in transitions) {
  12. if (el.style[t] !== undefined) {
  13. return transitions[t];
  14. }
  15. }
  16. return null;
  17. }
  18. function whichAnimationEvent() {
  19. const el = document.createElement('fakeelement');
  20. const transitions = {
  21. animation: 'animationend',
  22. OAnimation: 'oAnimationEnd',
  23. MSTransition: 'msAnimationEnd',
  24. MozAnimation: 'animationend',
  25. WebkitAnimation: 'webkitAnimationEnd',
  26. };
  27. for (const t in transitions) {
  28. if (el.style[t] !== undefined) {
  29. return transitions[t];
  30. }
  31. }
  32. return null;
  33. }
  34. CSSEvents = {
  35. transitionend: whichTransitionEvent(),
  36. animationend: whichAnimationEvent(),
  37. };