Skip to content

Commit e46c5de

Browse files
authored
fix: improve dropdown get relative position (#222)
1 parent d0877f0 commit e46c5de

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/common/dom.ts

+10-5
Original file line numberDiff line numberDiff line change
@@ -19,25 +19,30 @@ export function getDocumentRect() {
1919
const body = document.body;
2020
const html = document.documentElement;
2121

22+
const clientWidth = html.clientWidth;
23+
const clientHeight = html.clientHeight;
24+
2225
const height = Math.max(
2326
body.scrollHeight,
2427
body.offsetHeight,
25-
html.clientHeight,
28+
clientHeight,
2629
html.scrollHeight,
2730
html.offsetHeight
2831
);
2932

3033
const width = Math.max(
3134
body.scrollWidth,
3235
body.offsetWidth,
33-
html.clientWidth,
36+
clientWidth,
3437
html.scrollWidth,
3538
html.offsetWidth
3639
);
3740

3841
return {
3942
height,
4043
width,
44+
clientWidth,
45+
clientHeight,
4146
};
4247
}
4348

@@ -50,12 +55,12 @@ export function getRelativePosition(
5055
element: HTMLElement,
5156
relativePos: IPosition
5257
) {
53-
const page = getDocumentRect();
58+
const { clientWidth, clientHeight } = getDocumentRect();
5459
const anchorX = relativePos.x;
5560
const anchorY = relativePos.y;
5661

57-
const marginRight = page.width - anchorX;
58-
const marginBottom = page.height - anchorY;
62+
const marginRight = clientWidth - anchorX;
63+
const marginBottom = clientHeight - anchorY;
5964

6065
const viewHeight = element.offsetHeight;
6166
const viewWidth = element.offsetWidth;

0 commit comments

Comments
 (0)