Advertisement
Guest User

JS Scroll to ID

a guest
Jan 6th, 2014
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $(function() {
  2.     $('a[href*=#]:not([href=#])').click(function() {
  3.         if (location.pathname.replace(/^\//, '') == this.pathname.replace(/^\//, '')
  4.             || location.hostname == this.hostname) {
  5.  
  6.             var target = $(this.hash);
  7.             target = target.length ? target : $('[name=' + this.hash.slice(1) + ']');
  8.             if (target.length) {
  9.                 // scroll to the correct div or whatever.
  10.                 $('html,body').animate({
  11.                     scrollTop: target.offset().top
  12.                 }, 1000);
  13.                 return false;
  14.             }
  15.         }
  16.     });
  17. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement