Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Javascript
Posted by: Tommaso Vietina
Added: Dec 10, 2018 10:15 AM
Views: 18
Tags: no tags
  1. document.querySelectorAll('a[href^="#"]').forEach(anchor => {
  2.     anchor.addEventListener('click', function (e) {
  3.         e.preventDefault();
  4.  
  5.         document.querySelector(this.getAttribute('href')).scrollIntoView({
  6.             behavior: 'smooth'
  7.         });
  8.     });
  9. });