fix scroll helper
This commit is contained in:
parent
151e94bfac
commit
34edadcbb7
1 changed files with 8 additions and 5 deletions
|
@ -13,12 +13,15 @@ export default ({
|
||||||
if (typeof document === 'undefined') return;
|
if (typeof document === 'undefined') return;
|
||||||
document.onreadystatechange = () => {
|
document.onreadystatechange = () => {
|
||||||
if (document.readyState === 'complete') {
|
if (document.readyState === 'complete') {
|
||||||
const { hash } = location;
|
if (location.hash && location.hash.length > 0) {
|
||||||
const decoded = decodeURIComponent(hash);
|
const { hash } = location;
|
||||||
const targetAnchor = document.querySelector(decoded) ?? document.querySelector(hash);
|
|
||||||
|
|
||||||
if (targetAnchor && targetAnchor.offsetTop) {
|
const decoded = decodeURIComponent(hash);
|
||||||
window.scrollTo({ top: targetAnchor.offsetTop, behavior: 'smooth' });
|
const targetAnchor = document.querySelector(decoded) ?? document.querySelector(hash);
|
||||||
|
|
||||||
|
if (targetAnchor && targetAnchor.offsetTop) {
|
||||||
|
window.scrollTo({ top: targetAnchor.offsetTop, behavior: 'smooth' });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in a new issue