Skip to content

Instantly share code, notes, and snippets.

@strarsis
Forked from jpen365/one-page-nav.js
Created May 26, 2017 18:40
Show Gist options
  • Save strarsis/7436839db04b4d59407c56133655c2d2 to your computer and use it in GitHub Desktop.
Save strarsis/7436839db04b4d59407c56133655c2d2 to your computer and use it in GitHub Desktop.
One-page nav code for twenty seventeen
/*
One page nav code
*/
jQuery( document ).ready(function(){
/* Add padding and id's to each front page section */
jQuery( "h2.entry-title" ).each( function() {
var panelId = jQuery( this ).html().toLowerCase().replace(/\s+/g, "-");
jQuery( this ).wrapInner(function() {
return "<span style='padding-top:96px;' id='" + panelId + "'></span>";
})
})
/* Remove navigation link highlighting */
jQuery('#top-menu li').removeClass('current-menu-item current_page_item ');
/* Add highlighting on click */
jQuery('#top-menu li a').on('click', function(event) {
jQuery(this).parent().parent().find('li').removeClass('current-menu-item');
jQuery(this).parent().addClass('current-menu-item');
});
/* Check current URL and highlight nav for current page */
jQuery('#top-menu li a').each( function() {
var pageUrl = jQuery( location ).attr( 'href' );
var navUrl = jQuery( this ).attr( 'href' );
if ( navUrl == pageUrl ) {
jQuery( this ).parent().addClass('current-menu-item');
}
})
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment