Simple Vanilla JavaScript Context Menu

Category: Javascript , Menu & Navigation | October 1, 2015
Author: xylphid
Views Total: 3,242
Official Page: Go to website
Last Update: October 1, 2015
License: MIT


Simple Vanilla JavaScript Context Menu


A simple, animated, customizable modal-style context menu (right click menu) implemented in Vanilla JavaScript. The context menu will slide into your webpage with a fullscreen overlay as you right click on a specific container.

How to use it:

Load the necessary Vanilla JavaScript Framework in the html document.

<script src="/path/to/vanilla.min.js"></script>

Load the vanilla.contextmenu.js and vanilla.contextmenu.css in the document.

<script src="/path/to/vanilla.contextmenu.js"></script>
<link rel="stylesheet" href="/path/to/vanilla.contextmenu.css">

Add data-modal attribute to your links and use href attribute to define what should be opened in the modal.

<div id="example-1" class="example">
      <li data-highlight="highlight">Right click me</li>

The JavaScript to create the context menu.

vanilla.ctxm( '#example-1 li', {
  items: {
      highlight: { // Highlight the clicked image
          callback: function() {
              var target = vanilla.ctxm.getTarget();
                  .attr('data-highlight', 'highlight');;
      delete: { // Delete the clicked item
          callback: function() {
              var target = vanilla.ctxm.getTarget();
} );

Full configuration options.

vanilla.ctxm.defaults = {
  background: '#FFF',             // Background color
  border: '#CDCDCD',              // Border color
  fontSize: '14px',               // Font size
  headerText: 'Context menu',     // Menu header title
  iconPosition: 0,                // Icon position [0: left, 1: right]
  opacity: 0.5,                   // Overlay opacity
  overlay: '#000',                // Overlay color
  width: '200px'                  // Menu width

You Might Be Interested In:

Leave a Reply