×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Javascript
Posted by: Nicole Patten
Added: Sep 13, 2016 3:07 PM
Views: 2037
Tags: no tags
  1. $('a[href^="#"]').click(function() {
  2.         var target = $(this.hash);
  3.         var hash = this.hash;
  4.         if (target.length == 0) target = $('a[name="' + this.hash.substr(1) + '"]');
  5.         if (target.length == 0) target = $('html');
  6.         $('html, body').animate({ scrollTop: target.offset().top }, 800, 'swing', function (){
  7.             location.hash = hash;
  8.         });
  9.         return false;
  10.     });