Forked from oneblackcrayon/jquery.scrollTo.and.highlight.anchor.js
Last active
August 29, 2015 14:26
-
-
Save iamcanadian1973/b49cba99df8fe25efc28 to your computer and use it in GitHub Desktop.
When you want to highlight a navigation anchor with scrollTo
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
$(document).ready(function() { | |
$('nav.primary a').click(function(event) { // the elements you click to scroll | |
event.preventDefault(); | |
var link = this; // you need this if you are using hash links on ex: a href="#link" to id="link" | |
$.smoothScroll({ | |
offset: -160, // adjusts where the scroll will stop so the height of the scrolling element plus the height of the element you are scrolling to. | |
speed: 2000, | |
scrollTarget: link.hash | |
}); | |
}); | |
// waypoint alternative | |
// jsfiddle.net/senff/4D3bH/3/ | |
$('nav.primary a').click(function(){ | |
$('nav.primary a').removeClass('active'); | |
$(this).addClass('active'); | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment