Team:Aalto-Helsinki/ResponsiveNavScript
/* Scirpt for beautiful scrolling inside the page: smooth transitions and we show in what section the reader is. NOTE! Don't use for lab book -pages, they don't have .inner-container for the whole page length! Copy and paste this code and then change the .inner-container from the lower function to be for example .plasmids or whatever div class that goes through the whole content we want to have this navigation on. */
$('#sidenav a').on('click', function() {
var scrollAnchor = $(this).attr('data-scroll'), scrollPoint = $('section[data-anchor="' + scrollAnchor + '"]').offset().top - 28;
$('body,html').animate({ scrollTop: scrollPoint }, 500);
return false;
})
$(window).scroll(function() {
var windscroll = $(window).scrollTop(); if (windscroll >= 100) { $('.inner-container section').each(function(i) { if ($(this).position().top <= windscroll + 140) { $('#sidenav a.active').removeClass('active'); $('#sidenav a').eq(i).addClass('active'); } });
} else {
$('#sidenav a.active').removeClass('active'); $('#sidenav a:first').addClass('active'); }
}).scroll();