Hihi, I need that when I visit my webpage and # is present in the url go to that section. So What I did is to add an JS script
document.addEventListener('DOMContentLoaded', () => {
// setupScrolling();
setupTitle();
if (window.location.hash) {
const element = document.getElementById(window.location.hash);
if (element) {
const offset = element.offsetTop;
const a = offset - (document.querySelector('header')?.offsetHeight);
window.scroll({
top: offset,
behavior: 'smooth'
});
return false;
}
}
});
This is the script I added into my public/index.html
But, the behavior isn't correct.. Once the page scroll down to the section it will automatically go back to the top of the site and I don't know why.
Can anyone help me and tell me what I should do?