css Audio - Active file-generic CSS - Active Generic - Active HTML - Active JS - Active SVG - Active Text - Active file-generic Video - Active header Love html icon-new-collection icon-person icon-team numbered-list123 pop-out spinner split-screen star tv

Pen Settings

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URL's added here will be added as <link>s in order, and before the CSS in the editor. If you link to another Pen, it will include the CSS from that Pen. If the preprocessor matches, it will attempt to combine them before processing.

+ add another resource

You're using npm packages, so we've auto-selected Babel for you here, which we require to process imports and make it all work. If you need to use a different JavaScript preprocessor, remove the packages in the npm tab.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Use npm Packages

We can make npm packages available for you to use in your JavaScript. We use webpack to prepare them and make them available to import. We'll also process your JavaScript with Babel.

⚠️ This feature can only be used by logged in users.

Code Indentation

     

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

HTML Settings

Here you can Sed posuere consectetur est at lobortis. Donec ullamcorper nulla non metus auctor fringilla. Maecenas sed diam eget risus varius blandit sit amet non magna. Donec id elit non mi porta gravida at eget metus. Praesent commodo cursus magna, vel scelerisque nisl consectetur et.

            
              <div class="with-ctxmenu">
  Right click me !
</div>

<div class="hidden">
  <div id="ctxmenu-tpl">
    <ul class="ctxmenu-menu">
      <li>
        <a href="">Link with menu</a>

        <ul class="ctxmenu-menu">
          <li><a href="#">Link</a></li>
          <li><a href="#">Link again</a></li>
          <li><a href="#">And again</a></li>
          <li><a href="#">The last one</a></li>
        </ul>
      </li>

      <li>
        <a href="#">Link with menu</a>

        <ul class="ctxmenu-menu">
          <li><a href="#">First link</a></li>
          <li><a href="#">Second link</a></li>
        </ul>
      </li>

      <li>
        <a href="#">Link without menu</a>
      </li>

      <li>
        <a href="">Link without menu</a>
      </li>
    </ul>
  </div>
</div>
            
          
!
            
              @import url(https://fonts.googleapis.com/css?family=Ubuntu+Condensed);

body {
  background: #456;
  font-size: 0.9em;
  font-family: 'Ubuntu Condensed', sans-serif;
  color: #333;
}

.with-ctxmenu {
  width: 200px;
  margin: 80px auto;
  padding: 10px;
  text-align: center;
  border: 2px solid #333;
  border-radius: 10px;
  background: #789;
  font-size: 1.2em;
  font-weight: bold;
}

.hidden {
  display: none;
}

.ctxmenu {
  position: absolute;
  top: 0;
  left: 0;
  color: #333;
}
  .ctxmenu-menu {
    list-style: none;
    padding: 1px;
    margin: 0;
    border: 1px solid #888;
    background: #fefefe;
    border-radius: 2px;
    box-shadow: 2px 2px 3px #333;
  }
    .ctxmenu-menu li {
      position: relative;
    }
      .ctxmenu-menu a,
      .ctxmenu-menu a:visited {
        display: block;
        white-space: nowrap;
        padding: 3px 20px 3px 5px;
        border: 1px solid transparent;
        background: transparent;
        border-radius: 3px;
        color: #333;
        text-decoration: none;
      }
      .ctxmenu-menu a:hover {
        border-color: #0065a5;
        background: #7daac7;
      }
  .ctxmenu-menu .ctxmenu-menu {
    position: absolute;
    top: 0;
    left: 100%;
    display: none;
  }
    .ctxmenu-menu li:hover > .ctxmenu-menu {
      display: block;
    }
            
          
!
            
              var ctxmenu = {
  container: null
  
  // Initialize and add the div#ctxmenu container in the body
  ,init: function() {
    // hide the old ctxmenu
    this.hide();
    
    this.container = document.createElement('div');
    this.container.setAttribute('id', 'ctxmenu');
    // autohide
    this.container.className = 'ctxmenu hidden';
    
    document.body.appendChild(this.container);
  }
  
  // Setting the configuration of the ctxmenu
  ,set: function() {
    this.init();
    
    // override the default settings
    var settings = _.extend({
      content: null
      ,posX: 0
      ,posY: 0
    }, arguments[0] || {});

    // adding the content
    this.container.innerHTML = settings.content;
    
    // positionning
    this.container.style.left = settings.posX + 'px';
    this.container.style.top = settings.posY + 'px';
  }
  
  // Showing the ctxmenu
  ,show: function() {
    if(undefined !== arguments[0]) {
       this.set(arguments[0]); 
    }

    this.container.className = 'ctxmenu';
  }
  
  // Hide the ctxmenu
  ,hide: function() {
    if(this.container) {
      this.container.remove();
      this.container = null;
    }
  }
};

[].forEach.call(document.querySelectorAll('.with-ctxmenu'), function(el) {
  el.addEventListener('contextmenu', function(e) {
    // prevent the right click default action
    e.preventDefault();
    // prevent the auto kill
    e.stopPropagation();

    ctxmenu.show({
      content: document.getElementById('ctxmenu-tpl').innerHTML
      ,posX: e.clientX
      ,posY: e.clientY
    });
  });
});

// hide the contextmenu on left/right click
document.addEventListener('click', function() { ctxmenu.hide(); }, false);
document.addEventListener('contextmenu', function() { ctxmenu.hide(); }, false);

            
          
!
999px
🕑 One or more of the npm packages you are using needs to be built. You're the first person to ever need it! We're building it right now and your preview will start updating again when it's ready.
Loading ..................

Console