mirror of
https://github.com/elyby/accounts-frontend.git
synced 2025-05-31 14:11:58 +05:30
#139: preserve scrollTop, after open-close popup
This commit is contained in:
@@ -65,16 +65,21 @@ function restoreScroll() {
|
||||
setTimeout(() => {
|
||||
const id = hash.replace('#', '');
|
||||
const el = id ? document.getElementById(id) : null;
|
||||
const viewPort = document.getElementById('view-port');
|
||||
|
||||
if (!viewPort) {
|
||||
throw new Error('Can not find viewPort element');
|
||||
}
|
||||
|
||||
let y = 0;
|
||||
if (el) {
|
||||
const {scrollTop} = document.body;
|
||||
const {scrollTop} = viewPort;
|
||||
const {top} = el.getBoundingClientRect();
|
||||
|
||||
y = scrollTop + top - SCROLL_ANCHOR_OFFSET;
|
||||
}
|
||||
|
||||
scrollTo(y);
|
||||
scrollTo(y, viewPort);
|
||||
}, 100);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user