From 755f69bcbd80a0e2fd433a8ccd1427d856cda946 Mon Sep 17 00:00:00 2001 From: QuarkPixel Date: Thu, 18 Sep 2025 14:50:35 +0800 Subject: fix: display nothing when image not fully loaded --- src/shadow.js | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) (limited to 'src/shadow.js') 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() { -- cgit v1.2.3