“Smooth-Scroll.js” Code-Antworten

JavaScript glatte Schriftrolle zum Ankerelement

//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>
Grepper

So glätten Sie die Scroll in JavaScript

window.scrollTo({ top: 900, behavior: 'smooth' })
Cheerful Cockroach

Smooth-Scroll.js

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/smooth-scroll/16.1.0/smooth-scroll.min.js"></script>
Super Skunk

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen