Skip to content

Instantly share code, notes, and snippets.

@lenagroeger
Created November 24, 2015 16:06
Show Gist options
  • Save lenagroeger/e275fdef209f08b78b14 to your computer and use it in GitHub Desktop.
Save lenagroeger/e275fdef209f08b78b14 to your computer and use it in GitHub Desktop.
$(document).ready(function() {
$('.nav a').click(function(e) {
e.preventDefault();
var curInx = this.hash;
var target = $(curInx);
var targetOffset = target.offset().top;
$("body").animate({scrollTop: (targetOffset)}, 400, function() {
location.hash = curInx;
});
});
$(window).scroll(function() {
var sticky = function(index) {
$('li').removeClass('active'), $('.' + index + '-nav').addClass('active');
};
$('.section').each(function(){
var cur = $(this);
var curTop = cur.offset().top;
var curInx = cur.attr("id");
var sidebarTop = $('.'+curInx+'-nav').offset().top - 60;
if (sidebarTop > curTop) {
sticky(curInx);
}
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment