/simple-drop-down-menu

A simple Drop Down Menu Module

Primary LanguageJavaScriptMIT LicenseMIT

A Simple Drop Down Menu Module

Installation

npm install simple-ddm

Usage example

  • addToggle
import ddm from 'simple-ddm';

// trigger
const option = document.querySelector('.option');

// list
const listItems = document.querySelector('.links');

// add a class 'show' to the list when trigger is clicked
ddm.addToggle(option, listItems, 'show');
  • Optional callback
ddm.addToggle(option, listItems, 'show', () => {
  // do something
});
  • addFor
// this will find nodes for you
ddm.addFor('.option', '.links', 'show');
  • addForEach
// for multiple menus

// options class name
const optionClass = '.option';

// listItems class name
const listItemsClass = '.links';

// add a class 'show' to links list when it's trigger is clicked
ddm.addForEach(optionClass, listItemsClass, 'show');