Blog

Scrolling effect for Anchor Link

Posted on: 20 June 2018     Posted by: Freesize Workroom

Use the following code for the scrolling effect:

$(document).on('mousedown', 'a[href*="#"]:not([href="#"])', function() {

   $(this).blur();
   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 - 85)
         }, 1000);
      }
   }

});

Leave a Reply

Your email address will not be published.