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

Category: Javascript , Menu & Navigation | August 22, 2020
Author: nils-soderman
Views Total: 559 views
Official Page: Go to website
Last Update: August 22, 2020
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.addSeparator();

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

var contextMenu = CtxMenu("#myContainer");

Changelog:

07/23/2020

  • Fixed typo addSeperator -> addSeparator

10/22/2019

  • Fixed a position issue for pages with scrollbars

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:


One thought on “Custom Right-click Menu (Context Menu) In Vanilla JavaScript – CtxMenu

  1. premkumar

    HOW TO PLACE THIS IN LIST TAG?
    because, each list have seperate id

    Reply

Leave a Reply