Suggest a feature
×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Javascript
Posted by: Guille Pajares
Added: Jan 13, 2019 1:01 AM
Views: 19
Tags: no tags
  1. (function() {
  2.   $('a[href*="#"]:not([href="#"])').click(function() {
  3.     if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {
  4.       var 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
  9.         }, 1000);
  10.         return false;
  11.       }
  12.     }
  13.   });
  14. });