Skip to content

Commit 2e713dc

Browse files
authored
fix: StarportCraft margin caused errors in the coordinates (#57)
1 parent 79ca814 commit 2e713dc

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/components/StarportCraft.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ export const StarportCraft = defineComponent({
3939
height: `${rect.height}px`,
4040
margin: rect.margin,
4141
padding: rect.padding,
42-
transform: `translate3d(${rect.left}px,${rect.top}px,0px)`,
42+
transform: `translate3d(calc(${rect.left}px - ${rect.marginLeft}),calc(${rect.top}px - ${rect.marginTop}),0px)`,
4343
}
4444
if (!sp.value.isVisible || !sp.value.el) {
4545
return {

src/composables.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ export function useElementBounding(
1414
update,
1515
listen,
1616
pause,
17+
marginTop: '0px',
18+
marginLeft: '0px',
1719
margin: '0px',
1820
padding: '0px',
1921
})
@@ -29,9 +31,11 @@ export function useElementBounding(
2931
return
3032
const { height, width, left, top } = el.getBoundingClientRect()
3133
const domStyle = window.getComputedStyle(el)
34+
const marginTop = domStyle.marginTop
35+
const marginLeft = domStyle.marginLeft
3236
const margin = domStyle.margin
3337
const padding = domStyle.padding
34-
Object.assign(rect, { height, width, left, top: root!.scrollTop + top, margin, padding })
38+
Object.assign(rect, { height, width, left, top: root!.scrollTop + top, marginTop, marginLeft, margin, padding })
3539
}
3640
const raf = useRafFn(update, { immediate: false })
3741

0 commit comments

Comments
 (0)