diff options
| -rw-r--r-- | src/shadow.js | 23 |
1 files changed, 9 insertions, 14 deletions
diff --git a/src/shadow.js b/src/shadow.js index 4e06263..b02fad5 100644 --- a/src/shadow.js +++ b/src/shadow.js @@ -75,25 +75,20 @@ export default class Shadow { this.original.style.visibility = 'hidden'; if (!document.body.contains(this.element)) this.placeItself(); - // Wait for image to load before animating - if (this.element.naturalWidth === 0 || this.element.naturalHeight === 0) { - this.element.addEventListener( - 'load', - () => { - Animation.transformMatrix( - this.element, - this.originalPosition, - Animation.calculateFinalState(this.element), - ); - }, - { once: true }, - ); - } else { + // play animation + const animate = () => Animation.transformMatrix( this.element, this.originalPosition, Animation.calculateFinalState(this.element), ); + + if (this.element.naturalWidth === 0 || this.element.naturalHeight === 0) { + // Wait for image to load before animating + this.element.addEventListener('load', animate, { once: true }); + } else { + // animate directly if loaded + animate(); } } |
