jonnykates
9/21/2017 - 10:29 AM

Make anchor links scroll

Make anchor links scroll

//  Function to make all anchor links scroll to their targets--------------------------------------------------
$(function(){
  $('a[href*=#]:not([href=#])').click(function() {
    //console.log('Anchor clicked');
    if( location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname ){
      var target = this.hash;
      target = ( '#top' == target ) ? $('body') : $(target);
      target = target.length ? target : $('[name=' + this.hash.slice(1) +']');
      if( target.length ){
        $('html,body').animate({
          scrollTop: target.offset().top
        }, 1000);
        return false;
      }
    }
  });
});