0

I use an anchor link for my own site. And there is scroll animation. But because the header is sticky, it hides the title. So I want to get to a higher place where the anchor link goes. Is it possible?

HTML:

<li><a href="#example">Example</a></li>

JS:

document.querySelectorAll('a[href^="#"]').forEach(anchor => {
    anchor.addEventListener('click', function (e) {
        e.preventDefault();

        document.querySelector(this.getAttribute('href')).scrollIntoView({
            behavior: 'smooth'
        });
    });
});

0 Answers0