Skip to content

Instantly share code, notes, and snippets.

@chriskonnertz
Created March 17, 2016 08:28
Show Gist options
  • Save chriskonnertz/2899629644af05a4592c to your computer and use it in GitHub Desktop.
Save chriskonnertz/2899629644af05a4592c to your computer and use it in GitHub Desktop.
frontend.js
$(document).ready(function()
{
var navKey = 'navIndex';
var navIndex= sessionStorage.getItem(navKey);
var $nav = $('#header nav');
if (typeof navIndex === 'undefined') {
navIndex = 0;
}
if (window.location.pathname == '/') {
navIndex = 0;
sessionStorage.setItem(navKey, 0);
}
if (navIndex > 0) {
$nav.find('a').removeClass('active');
$nav.find('a:eq(' + navIndex + ')').addClass('active');
}
$nav.find('a').click(function(event)
{
sessionStorage.setItem(navKey, $(this).parent().index() - 1); // -1 because of icon li
});
$('#header nav .icon').click(function(event)
{
$nav.toggleClass('max');
})
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment