/ Published in: jQuery
Simply set the id in the content, and use a hash in the anchor to scroll to it.
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
$(function($) { $(".scroll a, .top-btn").click(function(event) { event.preventDefault(); $('html,body').animate({ scrollTop: $(this.hash).offset().top }, 500); }); });​ //usage <a href="#theContent">Scroll to content</a> <div id="theContent"> blah blah blah </div>