Skip to content

Instantly share code, notes, and snippets.

@ahmedsadman
Created February 7, 2019 09:55
Show Gist options
  • Save ahmedsadman/63c3444efd077fd4052ee5502b1a5f22 to your computer and use it in GitHub Desktop.
Save ahmedsadman/63c3444efd077fd4052ee5502b1a5f22 to your computer and use it in GitHub Desktop.
Smooth scroll to anchor (JQuery)
// Smooth Scrolling in Web pages - provides smooth scrolling when local anchor tag is clicked
// Source: http://www.catswhocode.com/blog/useful-jquery-code-snippets
// 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