Answers for "smooth-scroll.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
6

how to smooth scroll in javascript

window.scrollTo({ top: 900, behavior: 'smooth' })
Posted by: Guest on September-22-2020
0

smooth-scroll.js

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/smooth-scroll/16.1.0/smooth-scroll.min.js"></script>
Posted by: Guest on April-19-2021

Browse Popular Code Answers by Language