Posted By

benwellby on 11/09/10


Tagged

scroll link page jquery to top back animated


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

benwellby
tonicglop


jQuery – Back to top link


 / Published in: jQuery
 

Easy "back to top" scroll link

  1. HTML:
  2.  
  3. <a href="#" class="backToTop">Back to top</a>
  4.  
  5.  
  6. jQuery:
  7.  
  8. $(document).ready(function(){
  9. $('a.backToTop').click(function(){
  10. $('html, body').animate({scrollTop: '0px'}, 300);
  11. event.preventDefault();
  12. });
  13.  
  14. });

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: gabrielizaias on November 10, 2010

Use event.preventDefault() instead of return false and you are okay.

http://api.jquery.com/event.preventDefault/

Posted By: benwellby on December 17, 2010

Thanks gabrielizaias. That's some good advise! Fixed

You need to login to post a comment.