From 4bc4588cdeecf8bc286603ed9c641ce3182d60d3 Mon Sep 17 00:00:00 2001 From: unanmed <1319491857@qq.com> Date: Sat, 5 Oct 2024 23:23:35 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E8=8E=B7=E5=8F=96=E5=85=83=E7=B4=A0?= =?UTF-8?q?=E7=9A=84=E7=BB=9D=E5=AF=B9=E4=BD=8D=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/core/render/item.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/core/render/item.ts b/src/core/render/item.ts index a50af96..c828775 100644 --- a/src/core/render/item.ts +++ b/src/core/render/item.ts @@ -296,6 +296,18 @@ export abstract class RenderItem this.update(this); } + /** + * 获取当前元素的绝对位置(不建议使用,因为应当很少会有获取绝对位置的需求) + */ + getAbsolutePosition(): LocArr { + const { x, y } = this.transform; + if (!this.parent) return [x, y]; + else { + const [px, py] = this.parent.getAbsolutePosition(); + return [x + px, y + py]; + } + } + setAnchor(x: number, y: number): void { this.anchorX = x; this.anchorY = y;