Advertisement
Guest User

Untitled

a guest
Jul 23rd, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. // only polyfill .finished in browsers that already support animate()
  2. if (document.body.animate) {
  3.  
  4. // Chrome does not seem to expose the Animation constructor globally
  5. if (typeof Animation === 'undefined') {
  6. window.Animation = document.body.animate({}).constructor;
  7. }
  8.  
  9. if (!('finished' in Animation.prototype)) {
  10. Object.defineProperty(Animation.prototype, 'finished', {
  11. get() {
  12. if (!this._finished) {
  13. this._finished = this.playState === 'finished' ?
  14. Promise.resolve() :
  15. new Promise((resolve, reject) => {
  16. this.addEventListener('finish', resolve, {once: true});
  17. this.addEventListener('cancel', reject, {once: true});
  18. });
  19. }
  20. return this._finished;
  21. }
  22. });
  23. }
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement