Skip to content

Instantly share code, notes, and snippets.

Last active September 11, 2021 13:16
What would you like to do?
Anchor navigation powered by jquery.scrollTo
<!-- Include jQuery from somewhere, must use version 1.8 or above -->
<script type="text/javascript" src="//"></script>
<!-- Include latest jquery.scrollTo, can download from -->
<script type="text/javascript" src="//"></script>
<!-- Initialize the plugin, the contents of the script can be inlined here, of course -->
<script type="text/javascript" src="js/init.js"></script>
// You can avoid the document.ready if you put the script at the bottom of the page
$(document).ready(function() {
// Bind to the click of all links with a #hash in the href
$('a[href^="#"]').click(function(e) {
// Prevent the jump and the #hash from appearing on the address bar
// Scroll the window, stop any previous animation, stop on user manual scroll
// Check for more customizability
$(window).stop(true).scrollTo(this.hash, {duration:1000, interrupt:true});
Copy link

nickfmc commented Dec 10, 2016

seams to just be the interrupt:true setting that doesn't work on iOS changing this to false fixes the issue.

Copy link

Pomsou commented Jan 23, 2019

works perfect, thanks!

Copy link

dvigne commented Jan 5, 2020

Great little snippet, much appreciated!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment