jQuery Smooth Scroll to #Anchor


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

adapted from http://jquery14.com/day-05


Copy this code and paste it in your HTML
  1. // HTML:
  2. // <h1 id="anchor">Lorem Ipsum</h1>
  3. // <p><a href="#anchor" class="topLink">Back to Top</a></p>
  4.  
  5.  
  6. $(document).ready(function() {
  7.  
  8. $("a.topLink").click(function() {
  9. $("html, body").animate({
  10. scrollTop: $($(this).attr("href")).offset().top + "px"
  11. }, {
  12. duration: 500,
  13. easing: "swing"
  14. });
  15. return false;
  16. });
  17.  
  18. });

URL: http://jsbin.com/ayulu

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.