Answers for "scroll smooth to element push js"

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
0

smooth scrolling to div java script

var element = document.querySelector("#post-container");

// smooth scroll to element and align it at the bottom
element.scrollIntoView({ behavior: 'smooth'});
Posted by: Guest on September-03-2021

Browse Popular Code Answers by Language