summaryrefslogtreecommitdiff
path: root/src/shadow.js
diff options
context:
space:
mode:
authorEltrac <hi@guhub.cn>2025-09-17 00:48:15 +0800
committerEltrac <hi@guhub.cn>2025-09-17 00:48:15 +0800
commit3577505a7f2d43692819774f12ec43f8b38ef804 (patch)
treef6f885b0e5b73bb6bfefbc40514f501cd2fd96f2 /src/shadow.js
parentec2ee6bdbd06e4c348852d4b474ec65f14eea7a5 (diff)
fix: fix shadow positioning using getBoundingClientRect
Diffstat (limited to 'src/shadow.js')
-rw-r--r--src/shadow.js18
1 files changed, 10 insertions, 8 deletions
diff --git a/src/shadow.js b/src/shadow.js
index 462b3af..08e17d9 100644
--- a/src/shadow.js
+++ b/src/shadow.js
@@ -14,11 +14,12 @@ export default class Shadow {
this.original = image;
this.create(image);
+ const rect = this.element.getBoundingClientRect();
this.startingState = {
- top: this.element.offsetTop,
- left: this.element.offsetLeft,
- width: this.element.offsetWidth,
- height: this.element.offsetHeight
+ top: rect.top + window.scrollY,
+ left: rect.left + window.scrollX,
+ width: rect.width,
+ height: rect.height
}
return this;
@@ -32,10 +33,11 @@ export default class Shadow {
shadow.classList.add('libra-shadow');
// style and position shadow image
- shadow.style.top = image.offsetTop;
- shadow.style.left = image.offsetLeft;
- shadow.style.width = image.offsetWidth;
- shadow.style.height = image.offsetHeight;
+ const rect = image.getBoundingClientRect();
+ shadow.style.top = rect.top + window.scrollY;
+ shadow.style.left = rect.left + window.scrollX;
+ shadow.style.width = rect.width;
+ shadow.style.height = rect.height;
shadow.style.zIndex = this.zIndex;
document.body.appendChild(shadow);