Pen Settings

HTML

CSS

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

JavaScript

Babel includes JSX processing.

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

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

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.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <body>
  <div id="toggle" class="toggle">
    <i onclick="toggleMenu()" class="fa fa-eye" aria-hidden="true">&nbsp;Toggle Menu</i><br>
    <i onclick="nextSelection()" class="fa fa-external-link" aria-hidden="true">&nbsp;Change Selection</i><br>
    <i onclick="clicked()" class="fa fa-external-link" aria-hidden="true">&nbsp;Select</i><br>
    <i class="fa">Position: <select name="position" id="position" onchange="setPosition()">
      <option value="top_left">Top Left</option>
      <option value="top_right">Top Right</option>
      <option value="bottom_left">Bottom Left</option>
      <option value="bottom_right" selected>Bottom Right</option>
      </select></i><br>
    <i class="fa"><label for="touchMode">Touch Mode:</label><input type="checkbox" id="touchMode" onchange="toggleTouch()" checked></i><br>
    <i class="fa fa-keyboard-o" aria-hidden="true">&nbsp;Keyboard Enabled</i>
    <p style="font-size:50%; line-height: 1em; margin:0;">Menu Key (Next to Right-Alt) Opens/Closes<br>Arrow Up/Down Navigates<br>Enter selects</p>
  </div>

  
  <!-- VALID POSITIONS ARE: top_right, top_left, bottom_left and bottom_right
        CHANGE CLASS BELOW TO CHANGE POSITION. touchMode CAN ALSO BE ADDED TO ALWAY SHOW TOOLTIPS -->
  <div id="osm" class="bottom_right touchMode">
  <nav id="menuContainer" class="container" onmouseenter="mouseenterCB()" onmouseout="mouseoutCB();"> 
    <span class="buttons item" id="monitorOff" onclick="clicked('Turn Off Display')" tooltip="Turn Off Display">
      <i class="fa fa-television" aria-hidden="true"></i></span>
    <span class="buttons item" id="restart" onclick="clicked('Restart MagicMirror')" tooltip="Restart MagicMirror">
      <i class="fa fa-refresh" aria-hidden="true"></i></span>
    <span class="buttons item" id="reboot" onclick="clicked('Reboot')" tooltip="Reboot">
      <i class="fa fa-spinner" aria-hidden="true"></i></span>
    <span class="buttons item" id="shutdown" onclick="clicked('Shutdown')" tooltip="Shutdown">
      <i class="fa fa-power-off" aria-hidden="true"></i></span>
    <span onclick="toggleMenu()" class="buttons menu" tooltip="Close">
      <i class="fa fa-bars closed" aria-hidden="true"></i>
      <i class="fa fa-times opened" aria-hidden="true"></i>
    </span>
  </nav>
  </div>
</body>
              
            
!

CSS

              
                @import url(https://fonts.googleapis.com/css?family=Roboto:100,200,300,400,500);

body {
  margin: 60px;
  position: absolute;
  height: calc(100% - 120px);
  width: calc(100% - 120px);
  background: #000;
  color: #aaa;
  font-family: "Roboto Condensed", sans-serif;
  font-weight: 400;
  font-size: 2em;
  line-height: 1.5em;
  -webkit-font-smoothing: antialiased;
}

/************ MENU BUTTON ************/
.osm.control.top_right {
  top: -75;
  right: 75;
}

.osm.control.top_left {
  top: -75;
  left: -75;
}

.osm.control.bottom_right {
  bottom: 75;
  right: 75;
}

.osm.control.bottom_left {
  bottom: -75;
  left: -75;
}

/* Menu Button */
.osm.control {
  position: fixed;
  width: 150px;
  height: 150px;
  z-index: 55;
  border: 1px solid blue;
}

/* Show button when you hover near */
.osm.control:hover .container {
  opacity: 0.2;
  cursor: pointer !important;
}

.osm.control:hover {
  cursor: pointer !important;
}

/*Increase brightness when directly over*/
.osm.control .container:hover {
  opacity: 0.5;
}

.container {
  text-align: center;
  position: fixed;
  cursor: pointer !important;
  margin: 1em;
  /*opacity: 0.0;*/
}

[class*="_left"] .container { left: 0; }
[class*="_right"] .container { right: 0; }
[class*="top_"] .container { top: 0; }
[class*="bottom_"] .container { bottom: 0; }

.buttons {
  box-shadow: 0px 5px 11px -2px rgba(255, 255, 255, 0.18),
    0px 4px 12px -7px rgba(255, 255, 255, 0.15);
  border-radius: 50%;
/*   background-color: #222; */
  background-color: #fff;
  color: #333;
  display: block;
  position: relative;
  -webkit-transition: all .1s ease-out;
  transition: all .1s ease-out;
}

.buttons.menu {
  opacity: 0;
  width: 56px;
  height: 56px;
  margin: 20px auto 0;
  -webkit-transition: all .25s ease-out;
  transition: all .25s ease-out;
    -webkit-transition-delay: 500ms;
            transition-delay: 500ms;
}

.touchMode .buttons.menu {
  opacity: 0.8;
}

.container:hover .buttons.menu,
.openMenu .buttons.menu {
  opacity: 0.8;
      -webkit-transition-delay: 0ms;
            transition-delay: 0ms;
}

.buttons i {
  position: absolute;
  left: 50%;
  top: 50%;
  font-size: 85%;
  -webkit-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
}

.buttons.item i {
  font-size: 65%;
}

.container .buttons.menu .opened {
  opacity: 0 !important; 
  -webkit-transition: all .1s ease-out;
  transition: all .1s ease-out;
  -webkit-transition-delay: 0ms;
          transition-delay: 0ms;
}

.openMenu .buttons.menu .closed,
.container:hover .buttons.menu .closed {
  opacity: 0 !important; 
  -webkit-transition: all .1s ease-out;
  transition: all .1s ease-out;
    -webkit-transition-delay: 500ms;
            transition-delay: 500ms;
}

.container:hover .buttons.menu .opened,
.openMenu .buttons.menu .opened {
  opacity: 1 !important; 
  -webkit-transition: all .25s ease-in;
  transition: all .25s ease-in;
    -webkit-transition-delay: 600ms;
            transition-delay: 600ms;
}

.buttons:active, .buttons:focus, .buttons:hover, .buttons.selected {
  box-shadow: 0 0 4px rgba(255, 255, 255, .42),
    0 4px 8px rgba(255, 255, 255, .66);
}

[class*="bottom_"] .buttons.item {
  width: 40px;
  height: 40px;
  margin: 20px auto 0;
  opacity: 0;
  -webkit-transform: translateY(50px);
  -ms-transform: translateY(50px);
  transform: translateY(50px);
  -webkit-transition-delay: 500ms;
          transition-delay: 500ms;
}

[class*="top_"] .buttons.item {
  width: 40px;
  height: 40px;
  margin: 20px auto 0;
  opacity: 0;
  -webkit-transform: translateY(-50px);
      -ms-transform: translateY(-50px);
          transform: translateY(-50px);
  -webkit-transition-delay: 500ms;
          transition-delay: 500ms;
}

.container:hover .buttons.item,
.openMenu .buttons.item {
  opacity: 0.8;
  -webkit-transform: none;
  -ms-transform: none;
  transform: none;
    -webkit-transition-delay: 0ms;
            transition-delay: 0ms;
  margin: 15px auto 0;
}

/* Show tooltip content on hover */
.touchMode .buttons[tooltip]:before, 
.touchMode .buttons[tooltip]:after {
  visibility: visible !important;
  opacity: 0.6 !important;
}

.buttons.item[tooltip]:hover:before,
.buttons.item[tooltip]:hover:after,
.buttons.selected[tooltip]:before, 
.buttons.selected[tooltip]:after {
  visibility: visible !important;
  opacity: 1 !important;
}

.buttons.item[tooltip]:before {
  top: 50%;
  -webkit-transform: translateY(-50%);
  transform: translateY(-50%);
  border-radius: 2px;
  background: #585858;
  color: #fff;
  content: attr(tooltip);
  visibility: hidden;
  opacity: 0;
  padding: 0.7em 1em;
  margin-right: 1em;
  margin-left: 1em;
  position: absolute;
  white-space: nowrap;
  font-weight: 600;
  font-size: 0.5em;
  line-height: .7em;
}

[class*="_left"] .buttons.item[tooltip]:before {
  left: 100%;
}

[class*="_right"] .buttons.item[tooltip]:before {
  right: 100%;
}

.toggle i {
  display: inline-block;
  left: 50%;
  top: 50%;
  font-size: 85%;
}

.toggle {
  text-align: center;
  vertical-align: middle;
  position: fixed;
  top: 50%;
  left: 50%;
  width: 500px;
  height: auto;
  cursor: pointer !important;
  -webkit-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
}
              
            
!

JS

              
                NodeList.prototype.forEach = HTMLCollection.prototype.forEach =
  Array.prototype.forEach;
NodeList.prototype.indexOf = HTMLCollection.prototype.indexOf =
  Array.prototype.indexOf;

var currItem = -1;
var hovering = false;
var manualOpen = false;
var menuOpen = false;

Mousetrap.bind('up', function() { nextSelection(-1); });
Mousetrap.bind('down', function() { nextSelection(); });
Mousetrap.bind('enter', function() { clicked(); });
Mousetrap.addKeycodes({ 93: 'menu' });
Mousetrap.bind('menu', (e) => { 
  toggleMenu(); 
  e.preventDefault();
  return false;
}, 'keyup');

function toggleMenu(close) {
  var menu = document.getElementById("osm");
  currItem = -1;
  if (close || manualOpen) {
    clearSelection();
    menu.classList.remove("openMenu");
    manualOpen = false;
    menuOpen = hovering;
    return;
  } else {
    menu.classList.add("openMenu");
    menuOpen = true;
    manualOpen = true;
    return;
  }
}

function mouseenterCB() {
  hovering = true;
  menuOpen = true;
}

function mouseoutCB() {
  hovering = false;
  menuOpen = manualOpen;
}

function clearSelection() {
  var menu_ctr = document.getElementById("osm").children[0];
  menu_ctr.children.forEach(s => s.classList.remove("selected"));
}

function nextSelection(direction=1) {
  if (!menuOpen) { return false; }
  
  var menu = document.getElementById("osm");
  console.log(currItem, !currItem)
  var newI = currItem + direction;
  if (newI >= menu.children[0].children.length) {
    newI = 0;
  } else if (newI < 0) {
    newI = menu.children[0].children.length - 1;
  }
  console.log(currItem, direction, newI)
  currItem = newI;
 
  menu.children[0].children.forEach(s => {
    s.classList.toggle(
      "selected",
      menu.children[0].children.indexOf(s) === currItem
    );
  });
}

function clicked(id) {
  if (!id) {
    var menu = document.getElementById("osm").children[0];
    id = menu.children[currItem].getAttribute("tooltip");
  }
  toggleMenu(true);
  alert(`${id} Selected.`);
}

// DEMO FUNCTIONS
function setPosition() {
  var pos = document.getElementById("position").value;
  var menu = document.getElementById("osm");
  var nav = menu.children[0];
  menu.classList.toggle("top_left", pos === "top_left");
  menu.classList.toggle("top_right", pos === "top_right");
  menu.classList.toggle("bottom_left", pos === "bottom_left");
  menu.classList.toggle("bottom_right", pos === "bottom_right");
  var menuBtn = nav.getElementsByClassName("buttons menu")[0];
  if (pos.startsWith("bottom")) {
    nav.appendChild(menuBtn);
  } else {
    nav.insertBefore(menuBtn, nav.children[0]);
  }
}

function toggleTouch() {
  var menu = document.getElementById("osm");
  var touch = document.getElementById("touchMode");
  console.log(touch);
  menu.classList.toggle("touchMode", touch.checked === true);
}


              
            
!
999px

Console