DAC of Design Action
10/25/2016 - 12:00 AM

Smooth Scrolling

Smooth Scrolling

Purpose

Give smooth Scrolling to the anchor tags

Installation

Add to your js file, it uses jQuery

Use

It should just work.

$(document).ready(function(){
$(function() {
    var topoffset = 90; // the margin that needs to be given on the top
  	$('a[href*="#"]:not([href="#"])').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 - topoffset
            }, 1000);
          return false;
        }
      }
	  });
  });
});