Simple jQuery page scroller


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

Example in 'jQuery enlightenment'

Simple way to jump smoothly down the page without the use of a plugin.


Copy this code and paste it in your HTML
  1. /**
  2.  * HTML setup as a list of anchors set vertically down the page
  3.  */
  4.  
  5. //Click an anchor
  6. $("a").click(function(e){
  7. //Animate the html and body
  8. $("html, body").animate({
  9. //Set the CSS property scrollTop to the next anchors top value
  10. scrollTop: $(this).parent('li').next().find("a").offset().top
  11. }, 1000);//1 second scroll (add some easing for a smoother look)
  12. return false;
  13. });

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.