Custom Right-click Menu (Context Menu) In Vanilla JavaScript – CtxMenu

Category: Javascript , Menu & Navigation | August 13, 2019
Author: nils-soderman
Views Total: 75
Official Page: Go to website
Last Update: August 13, 2019
License: MIT

Preview:

Custom Right-click Menu (Context Menu) In Vanilla JavaScript – CtxMenu

Description:

CtxMenu is a dynamic, customizable context menu plugin to replace the native browser right-click menu.

How to use it:

Add the CtxMenu plugin’s JavaScript to the page.

<script src="/path/to/CtxMenu/CtxMenu.js"></script>

Create a new context menu for the entire page.

var contextMenu = CtxMenu();

Add items together with onClick functions, custom icons, list index to the context menu.

contextMenu.addItem("Item 1", function(){
  // fired on click
});

contextMenu.addItem("Item 2", function(){
  // fired on click
},Icon = "icon.png", 3);

Add a separator to the context menu.

contextMenu.addSeperator();

You can also attach the context menu to any container element you specify.

var contextMenu = CtxMenu("#myContainer");

Changelog:

08/13/2019

  • Removed CtxMenuItem class & changed some variables to constants

08/10/2019

  • Fixed an issue that could break the menu if the page had scrollbars

08/04/2019

  • Added index option to addSeperator()

08/02/2019

  • added min & max width to the image icon

08/01/2019

  • The box-shadow now uses rgba instead of hex
  • Fixed elements not being detected if it had multiple class names

You Might Be Interested In:


Leave a Reply