smooth scrolling when clicking an anchor link

Solutions on MaxInterview for smooth scrolling when clicking an anchor link by the best coders in the world

showing results for - "smooth scrolling when clicking an anchor link"
Valeria
08 Nov 2017
1// smooth scrolling when clicking an anchor link 
2$('.nav-item a').on('click', function () {
3    if (location.pathname.replace(/^\//, '') === this.pathname.replace(/^\//, '') && location.hostname === this.hostname) {
4        let target = $(this.hash);
5        target = target.length ? target : $('[name=' + this.hash.slice(1) + ']');
6        if (target.length) {
7            html_body.animate({
8                scrollTop: target.offset().top - 0
9            }, 1500);
10            return false;
11        }
12
13    }
14});
Camille
07 Feb 2019
1html{scroll-behavior:smooth}
2