Smooth Scroll To Anchor

smooth scroll to anchor
/* Just use Native HTML Smooth Scroll */
html {
scroll-behavior: smooth;
}
smooth scroll css
html {
scroll-behavior: smooth;
}

/* No support in IE, or Safari
You can use this JS polyfill for those */
http://iamdustan.com/smoothscroll/
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>
smooth scroll on anchor tag
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();

document.querySelector(this.getAttribute('href')).scrollIntoView({
behavior: 'smooth'
});
});
});

 

 

Leave a Comment