#139: preserve scrollTop, after open-close popup

This commit is contained in:
SleepWalker
2016-06-04 10:39:24 +03:00
parent f22ae1ba54
commit a9b0c6804b
5 changed files with 19 additions and 6 deletions

View File

@@ -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);
}