diff options
| author | QuarkPixel <m2462864403@gmail.com> | 2025-09-18 14:50:35 +0800 |
|---|---|---|
| committer | QuarkPixel <m2462864403@gmail.com> | 2025-09-18 14:50:35 +0800 |
| commit | 755f69bcbd80a0e2fd433a8ccd1427d856cda946 (patch) | |
| tree | 77da545c02367861e6a0fbdb104c75bf256e913e /src/shadow.js | |
| parent | b66d25addeefbc60b01adbbf86fa2272700266fe (diff) | |
fix: display nothing when image not fully loaded
Diffstat (limited to 'src/shadow.js')
| -rw-r--r-- | src/shadow.js | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/src/shadow.js b/src/shadow.js index be7eb9c..5435532 100644 --- a/src/shadow.js +++ b/src/shadow.js @@ -75,11 +75,26 @@ export default class Shadow { this.original.style.visibility = 'hidden'; if (!document.body.contains(this.element)) this.placeItself(); - Animation.transformMatrix( - this.element, - this.originalPosition, - Animation.calculateFinalState(this.element) - ); + // 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 { + Animation.transformMatrix( + this.element, + this.originalPosition, + Animation.calculateFinalState(this.element), + ); + } } close() { |
