Skip to content

Instantly share code, notes, and snippets.

@jveldboom
Created June 23, 2013 01:28
Show Gist options
  • Save jveldboom/5843364 to your computer and use it in GitHub Desktop.
Save jveldboom/5843364 to your computer and use it in GitHub Desktop.
Smooth scrolling to #anchor
// HTML:
// <h1 id="anchor">Lorem Ipsum</h1>
// <p><a href="#anchor" class="topLink">Back to Top</a></p>
$(document).ready(function() {
$("a.topLink").click(function() {
$("html, body").animate({
scrollTop: $($(this).attr("href")).offset().top + "px"
}, {
duration: 500,
easing: "swing"
});
return false;
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment