Answers for "href smooth scroll"

1

smooth scroll on anchor tag

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

        document.querySelector(this.getAttribute('href')).scrollIntoView({
            behavior: 'smooth'
        });
    });
});
Posted by: Guest on October-06-2021

Browse Popular Code Answers by Language