Posted By

adambundy on 12/15/09


Tagged


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

adambundy
luman


jQuery smooth scroll to an anchor


 / Published in: jQuery
 

  1. $('a[href*=#]').click(function() {
  2. if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
  3. && location.hostname == this.hostname) {
  4. var $target = $(this.hash);
  5. $target = $target.length && $target
  6. || $('[name=' + this.hash.slice(1) +']');
  7. if ($target.length) {
  8. var targetOffset = $target.offset().top;
  9. $('html,body')
  10. .animate({scrollTop: targetOffset}, 900);
  11. return false;
  12. }
  13. }
  14. });

Report this snippet  

You need to login to post a comment.