-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathgetScrollPosition.ts
35 lines (34 loc) · 1003 Bytes
/
getScrollPosition.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
27
28
29
30
31
32
33
34
35
/**
* Get slide to top and bottom return 'top' 'bottom', recommend using limit flow
*
* @deprecated will be removed in the next major release.
* @since 1.0.2
* @returns - position
*/
function getScrollPosition() {
const innerH =
window.innerHeight || document.documentElement.clientHeight || document.body.clientHeight
const docScrollTop = document.documentElement.scrollTop
const bodyScrollTop = document.body.scrollTop
const docScrollHeight = document.documentElement.scrollHeight
const bodyScrollHeight = document.body.scrollHeight
let scrollT = 0,
scrollH = 0
if (docScrollTop === 0) {
scrollT = bodyScrollTop
scrollH = bodyScrollHeight
if (bodyScrollTop === 0) {
return 'top'
}
} else {
scrollT = docScrollTop
scrollH = docScrollHeight
}
// if(bodyScrollTop === 0 && docScrollTop === 0){
// return 'top';
// }
if (innerH + Math.floor(scrollT) === scrollH || innerH + Math.ceil(scrollT) === scrollH) {
return 'bottom'
}
}
export default getScrollPosition