scrollTo jQuery


/ Published in: jQuery
Save to your folder(s)

scrollTo jQuery


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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.