A JavaScript library to make navigation menus activate the item based on currently in view section.




You can pass options as the second parameter on plugin initialization. For example:

var elm = document.querySelector('#main-header');
var ms = new MenuSpy(elm, {
  activeClass: 'current-item'
Option Type Default Description
menuItemSelector String a[href^="#"] Menu items selector.
activeClass String active Class applied on menu item relative to the currently visible section.
threshold Integer 15 Ammount of space between your menu and the next section to be activated.
enableLocationHash Boolean true Enable or disable browser's hash location change.
hashTimeout Integer 600 Timeout to apply browser's hash location.
callback Function function(currentItem) {} A function to be called every time a new menu item activates.