Posted By

cfleschhut on 01/20/10


Tagged

javascript jquery


Versions (?)

Who likes this?

14 people have marked this snippet as a favorite

alejandrosuch
gabbo
JamesFillingham
Kurt
czachor
boton
Snowalker
ottoman153
dato
r34194r
Mench59
ringo380
Some0ne
mikael12


jQuery Smooth Scroll to #Anchor


 / Published in: jQuery
 

URL: http://jsbin.com/ayulu

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

  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. });

Report this snippet  

Comments

RSS Icon Subscribe to comments
Posted By: Snowalker on November 30, 2011

maybe I'm doing something wrong but this is not working :(

You need to login to post a comment.