forked from InhiblabCore/vue-hooks-plus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrect.ts
26 lines (23 loc) · 744 Bytes
/
rect.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
const getScrollTop = (el: Document | Element) => {
if (el === document || el === document.documentElement || el === document.body) {
return Math.max(
window.pageYOffset,
document.documentElement.scrollTop,
document.body.scrollTop
);
}
return (el as Element).scrollTop;
};
const getScrollHeight = (el: Document | Element) => {
return (
(el as Element).scrollHeight ||
Math.max(document.documentElement.scrollHeight, document.body.scrollHeight)
);
};
const getClientHeight = (el: Document | Element) => {
return (
(el as Element).clientHeight ||
Math.max(document.documentElement.clientHeight, document.body.clientHeight)
);
};
export { getScrollTop, getScrollHeight, getClientHeight };