-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathutils.js
More file actions
23 lines (21 loc) · 744 Bytes
/
Copy pathutils.js
File metadata and controls
23 lines (21 loc) · 744 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
export const scrollToElement = (elementRef, scrollableParentRef) => {
const elementCheck = setInterval(() => {
const element = elementRef && elementRef.current;
const scrollingElement = scrollableParentRef && scrollableParentRef.current;
if (scrollableParentRef && element) {
scrollingElement.scrollTo({
top: element.offsetTop - scrollingElement.offsetTop,
left: 0,
behavior: 'smooth',
});
} else if (element) {
const scrollTop = window.pageYOffset || document.documentElement.scrollTop;
window.scrollTo({
top: element.getBoundingClientRect().top + scrollTop,
left: 0,
behavior: 'smooth',
});
}
clearInterval(elementCheck);
}, 100);
};