Posted By

Guitaraholic on 04/07/11


Tagged

java jquery scrolling smooth


Versions (?)

Java # smooth scroll to element


 / Published in: JavaScript
 

URL: http://elziah.com

  1. $(function(){
  2.  
  3. $('a[href*=#]').click(function() {
  4.  
  5. if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'')
  6.  
  7.  
  8.  
  9. && location.hostname == this.hostname) {
  10.  
  11. var $target = $(this.hash);
  12.  
  13. $target = $target.length && $target || $('[name=' + this.hash.slice(1) +']');
  14.  
  15.  
  16.  
  17.  
  18. if ($target.length) {
  19.  
  20. var targetOffset = $target.offset().top;
  21.  
  22. $('html,body').animate({scrollTop: targetOffset}, 1000);
  23.  
  24.  
  25.  
  26.  
  27. return false;
  28.  
  29. }
  30.  
  31. }
  32.  
  33. });
  34.  
  35. });

Report this snippet  

You need to login to post a comment.