Answers for "jquery scrollTop smooth"

2

smooth scroll to top jquery

window.scrollTo({top: 0, behavior: 'smooth'});
Posted by: Guest on October-01-2020
7

javascript smooth scroll to anchor element

//add smooth scrolling when clicking any anchor link
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
    anchor.addEventListener('click', function (e) {
        e.preventDefault();
        document.querySelector(this.getAttribute('href')).scrollIntoView({
            behavior: 'smooth'
        });
    });
});
//<a href="#someOtherElementID"> Go to Other Element Smoothly </a>
Posted by: Guest on August-02-2019

Code answers related to "Javascript"

Browse Popular Code Answers by Language