javascript - Improve smooth scrolling in order to get anchor links on the URL Adress bar -


as title says, found this script smooth scrolling , improved little, looks this:

  $('a[href*=#]:not([href=#])').on('click', function() {     if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) {       var target = $(this.hash);       target = target.length ? target : $('[name=' + this.hash.slice(1) +']');       if (target.length) {         $('html,body').animate({           scrolltop: target.offset().top - 50 // in case 50px before         }, 1000);         return false;       }     }   }); 

it triggers when user click on anchor link.

the problem url address doesn't change. i'll change user url address bar, in order anchor link displayed everytime user click on link makes him scroll.

thanks in advance give me.

ps: can see website i'm testing here.

you can change address using:

if (target.length) {     history.replacestate(null, null, this.hash);     $('html,body').animate({         scrolltop: target.offset().top - 50 // in case 50px before     }, 1000);     return false; } 

if want update browser history, use instead:

history.pushstate(null, null, this.hash); 

more info


Comments

Popular posts from this blog

ruby - Trying to change last to "x"s to 23 -

jquery - Clone last and append item to closest class -

css - Can I use the :after pseudo-element on an input field? -