Posted By

thewickedchemist on 06/02/12


Tagged

scroll jquery smooth


Versions (?)

Who likes this?

1 person have marked this snippet as a favorite

BrockSamsom


Smooth Scrolling to Any ID


 / Published in: jQuery
 

Simply set the id in the content, and use a hash in the anchor to scroll to it.

  1. $(function($) {
  2. $(".scroll a, .top-btn").click(function(event) {
  3. event.preventDefault();
  4. $('html,body').animate({
  5. scrollTop: $(this.hash).offset().top
  6. }, 500);
  7. });
  8. });‚Äč
  9.  
  10. //usage
  11.  
  12. <a href="#theContent">Scroll to content</a>
  13.  
  14.  
  15. <div id="theContent">
  16. blah blah blah
  17. </div>

Report this snippet  

You need to login to post a comment.