-
-
Save joshuacharleslake/2c92d621fcdae5175a1bb7f499c489b8 to your computer and use it in GitHub Desktop.
A simple jQuery script that will allow for smooth scrolling on a page when clicking on an anchor point.
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
<!-- ENSURE BELOW PASTES DIRECTLY INTO THE HEAD OF THE PAGE --> | |
<!-- SMOOTH SCROLL --> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script> | |
<script> | |
$(function() { | |
$('a[href*=#]:not([href=#])').click(function() { | |
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) { | |
var target = $(this.hash); | |
target = target.length ? target : $('[name=' + this.hash.slice(1) +']'); | |
if (target.length) { | |
$('html,body').animate({ | |
scrollTop: target.offset().top | |
}, 1000); | |
return false; | |
} | |
} | |
}); | |
}); | |
</script> | |
<!-- End of SMOOTH SCROLL --> | |
<!--- HTML EXAMPLE BELOW --> | |
<a href="#point"></a> | |
<div name="point"></div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment