forked from dequelabs/axe-core
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget-scroll-state.js
More file actions
43 lines (39 loc) · 1.01 KB
/
get-scroll-state.js
File metadata and controls
43 lines (39 loc) · 1.01 KB
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
36
37
38
39
40
41
42
43
import getScroll from './get-scroll';
/**
* Create an array scroll positions from descending elements
*/
function getElmScrollRecursive(root) {
// Need to also get .childNodes since SVGs in IE don't have .children.
return Array.from(root.children || root.childNodes || []).reduce(
(scrolls, elm) => {
const scroll = getScroll(elm);
if (scroll) {
scrolls.push(scroll);
}
return scrolls.concat(getElmScrollRecursive(elm));
},
[]
);
}
/**
* Get the scroll position of all scrollable elements in a page
* @deprecated
*/
function getScrollState(win = window) {
const root = win.document.documentElement;
const windowScroll = [
win.pageXOffset !== undefined
? {
elm: win,
top: win.pageYOffset,
left: win.pageXOffset
}
: {
elm: root,
top: root.scrollTop,
left: root.scrollLeft
}
];
return windowScroll.concat(getElmScrollRecursive(document.body));
}
export default getScrollState;