anchores fix (#967)

This commit is contained in:
trean
2024-06-13 16:24:30 +02:00
committed by GitHub
parent 04303b275b
commit cc45bdc9a1
2 changed files with 2 additions and 14 deletions
@@ -19,17 +19,6 @@ export function scrollIntoViewWithOffset(id, offset) {
top: targetPosition,
behavior: 'smooth',
});
return new Promise((resolve) => {
const scrollHandler = () => {
// resolve promise when scroll is finished
if (window.scrollY === Math.floor(targetPosition)) {
window.removeEventListener('scroll', scrollHandler);
resolve();
}
};
window.addEventListener('scroll', scrollHandler);
});
}
export function isNodeList(list) {
@@ -24,9 +24,8 @@ document.addEventListener('DOMContentLoaded', function (event) {
const target = anchor.getAttribute('href');
anchor.addEventListener('click', function (e) {
e.preventDefault();
scrollIntoViewWithOffset(target.replace('#', ''), offset).then(() => {
history.pushState(null, null, target);
});
history.pushState(null, null, target);
scrollIntoViewWithOffset(target.replace('#', ''), offset);
});
});
});