Created
February 7, 2019 09:55
-
-
Save ahmedsadman/63c3444efd077fd4052ee5502b1a5f22 to your computer and use it in GitHub Desktop.
Smooth scroll to anchor (JQuery)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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