Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR CSS

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'
        });
    });
});
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #smooth #scroll #anchor #tag
ADD COMMENT
Topic
Name
6+9 =