MenuSpy

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

Features

Usage

Options

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.
hashTimeout Integer 600 Timeout to apply browser's hash location.
callback Function function(anchorElm, targetElm) {} A function to be called every time a new menu item activates.

Examples