mirror of
https://github.com/elyby/accounts-frontend.git
synced 2024-11-19 06:32:58 +05:30
#131:s scroll to anchor considering header height
This commit is contained in:
parent
02a18aee13
commit
664a3a6de7
12
src/index.js
12
src/index.js
@ -53,6 +53,7 @@ userFactory(store)
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const SCROLL_ANCHOR_OFFSET = 80; // 50 + 30 (header height + some spacing)
|
||||||
/**
|
/**
|
||||||
* Scrolls to page's top or #anchor link, if any
|
* Scrolls to page's top or #anchor link, if any
|
||||||
*/
|
*/
|
||||||
@ -63,11 +64,16 @@ function restoreScroll() {
|
|||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
const id = hash.replace('#', '');
|
const id = hash.replace('#', '');
|
||||||
const el = id ? document.getElementById(id) : null;
|
const el = id ? document.getElementById(id) : null;
|
||||||
|
|
||||||
|
let y = 0;
|
||||||
if (el) {
|
if (el) {
|
||||||
el.scrollIntoView();
|
const {scrollTop} = document.body;
|
||||||
} else {
|
const {top} = el.getBoundingClientRect();
|
||||||
window.scrollTo(0, 0);
|
|
||||||
|
y = scrollTop + top - SCROLL_ANCHOR_OFFSET;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
window.scrollTo(0, y);
|
||||||
}, 100);
|
}, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user