scottliv
10/13/2017 - 5:19 PM

smooth scroll

smooth scroll


$(function () {
  //Smooth Scroll from https://css-tricks.com/snippets/jquery/smooth-scrolling/
  //Updated to account for fixed header height
  // Select all links with hashes
    $("a[href*='#']:not([href='#'])").click(function () {
      if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '') && location.hostname == this.hostname) {
        var target = $(this.hash);
        var headerHeight = $("header").height();
        var scrollToPosition = $(target).offset().top - headerHeight;
        target = target.length ? target : $('[name=' + this.hash.slice(1) + ']');
        if (target.length) {
          $('html,body').animate({
            scrollTop: scrollToPosition}, 800);
          return false;
        }
      }
    });