Skip to content

Commit 71cd92a

Browse files
committed
fix: correct graphic vertex position in nested html structures
1 parent f294f04 commit 71cd92a

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

packages/front/src/utils/graphic-vertex-picker.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export class GraphicVertexPicker implements OBC.Disposable {
9797
}
9898
this._preview.style.zIndex = "999";
9999
this._preview.style.pointerEvents = "none";
100-
this._preview.style.position = "fixed";
100+
this._preview.style.position = "absolute";
101101
this._preview.style.top = "0";
102102
this._preview.style.left = "0";
103103
}
@@ -299,15 +299,25 @@ export class GraphicVertexPicker implements OBC.Disposable {
299299
const casters = this._components.get(OBC.Raycasters);
300300
const caster = casters.get(this.world);
301301
const mousePosition = caster.mouse.rawPosition;
302-
this._preview.style.transform = `translate(-50%, -50%) translate(${mousePosition.x}px, ${mousePosition.y}px)`;
302+
const domElement = this.world.renderer!.three.domElement;
303+
const rect = domElement.getBoundingClientRect();
304+
const x = mousePosition.x - rect.left;
305+
const y = mousePosition.y - rect.top;
306+
this._preview.style.transform = `translate(-50%, -50%) translate(${x}px, ${y}px)`;
303307
}
304308

305309
private showPointer() {
306310
if (!this.world) return;
307311
if (this._pointerVisible) return;
308312
this._pointerVisible = true;
309313
const domElement = this.world.renderer!.three.domElement;
310-
domElement.parentElement?.appendChild(this._preview);
314+
const parent = domElement.parentElement;
315+
if (!parent) return;
316+
const style = getComputedStyle(parent);
317+
if (style.position === "static") {
318+
parent.style.position = "relative";
319+
}
320+
parent.appendChild(this._preview);
311321
}
312322

313323
private hidePointer() {

0 commit comments

Comments
 (0)