Skip to content

Instantly share code, notes, and snippets.

View nicolebeaumont's full-sized avatar

Nicole Penn nicolebeaumont

View GitHub Profile
@nicolebeaumont
nicolebeaumont / smooth-scroll-vanilla.js
Created August 1, 2020 09:53
Animated smooth scroll plain js, simple
// attach animated scroll to all hash links
document.querySelectorAll("a[href^='#']").forEach(element => {
const [, id] = element.href.split('#')
element.addEventListener("click", e => {
e.preventDefault()
document
.getElementById(id)
.scrollIntoView({behavior: 'smooth'});
})
});