Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Javascript
Posted by: Marosi Dóra
Added: Dec 8, 2020 11:55 AM
Views: 5
Tags: no tags
  1. // smooth scroll
  2. document.querySelectorAll('a[href^="#"]').forEach(anchor => {
  3.    anchor.addEventListener('click', function (e) {
  4.        e.preventDefault();
  5.        if (this.getAttribute('href') !== "#") {
  6.            document.querySelector(this.getAttribute('href')).scrollIntoView({
  7.                behavior: 'smooth'
  8.            });
  9.        }
  10.    });
  11. });