From b66d25addeefbc60b01adbbf86fa2272700266fe Mon Sep 17 00:00:00 2001 From: QuarkPixel Date: Thu, 18 Sep 2025 14:49:16 +0800 Subject: fix: viewport change causes animation position error --- src/shadow.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) (limited to 'src') diff --git a/src/shadow.js b/src/shadow.js index e36affa..be7eb9c 100644 --- a/src/shadow.js +++ b/src/shadow.js @@ -51,10 +51,27 @@ export default class Shadow { * ============ */ + updateOriginalPosition() { + const rect = this.original.getBoundingClientRect(); + this.originalPosition = { + top: rect.top + window.scrollY + config.offset.y, + left: rect.left + window.scrollX + config.offset.x, + width: rect.width, + height: rect.height, + }; + } + open() { this.isOpen = true; this.element.classList.add('open'); + // Update original position before animation in case viewport changed + this.updateOriginalPosition(); + this.element.style.top = `${this.originalPosition.top}px`; + this.element.style.left = `${this.originalPosition.left}px`; + this.element.style.width = `${this.originalPosition.width}px`; + this.element.style.height = `${this.originalPosition.height}px`; + this.original.style.visibility = 'hidden'; if (!document.body.contains(this.element)) this.placeItself(); -- cgit v1.2.3