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 is required to process package imports. If you need a different preprocessor remove all packages first.

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

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 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.

HTML

              
                <div class="wrapper">
  <div class="box">
    <div class="grid">
    </div>
  </div>
  <button id="one">Mode 1</button>
  <button id="two">Mode 2</button>
  <button id="three">Mode 3</button>
  <button id="four">Mode 4</button>
  <button id="five">Mode 5</button>
  <button id="reset">RESET</button>
</div>


              
            
!

CSS

              
                body{
  background-color: #444;
  background: repeating-linear-gradient(45deg, #2b2b2b 0%, #2b2b2b 10%, #222222 0%, #222222 50%) 0 / 15px 15px;
}

button{
  background-color: #4d4d4d; 
  border: none;
  color: white;
  padding: 0.5rem 1rem;
  text-align: center;
  text-decoration: none;
  display: inline-block;
  font-size: 12px;
}

.wrapper{
  text-align: center;
}

.box{
  margin: 2rem auto; 
  border: 5px solid #2d2d2d;
  height: 270px;
  width: 80px;
  border-radius: 10px;
}

.grid{
  display: grid;
  grid-auto-rows: 50px;
  gap: 1rem;
  padding: 10px;
}

.high-beam{
  background-color: #fff;
  height: 3rem;
  width: 3rem;
  border-radius: 50%;
  margin:  auto;
  box-shadow: 0 0 5px #fff, 0 0 10px #fff, 0 0 15px #fff, 0 0 20px red, 0 0 35px red, 0 0 40px red;
}

.low-beam{
  background-color: #fff;
  height: 3rem;
  width: 3rem;
  border-radius: 50%;
  margin:  auto;
  box-shadow: 0 0 5px #fff, 0 0 10px red, 0 0 15px red, 0 0 20px red, 0 0 35px red, 0 0 40px red;
}

.shine{
  background-color: #fff;
  animation: neon 0.2s ease infinite;
}

.alter-one{
  background-color: #fff;
  animation: neon 0.375s ease infinite;
}

.alter-two{
  animation: neon2 0.78s ease infinite;
}

.off{
  background-color: grey;
  box-shadow: none;
}

@keyframes neon {
  from {
    box-shadow: 0 0 10px #fff, 0 0 20px #fff, 0 0 30px #fff, 0 0 40px red, 0 0 70px red, 0 0 80px red, 0 0 100px red, 0 0 150px red, 0 0 200px red;
  }
  to {
    box-shadow: 0 0 5px #fff, 0 0 10px #fff, 0 0 15px #fff, 0 0 20px red, 0 0 35px red, 0 0 40px red, 0 0 50px red, 0 0 75px red;
  }
}

@keyframes neon2 {
  from {
    box-shadow: 0 0 10px #fff, 0 0 20px #fff, 0 0 30px #fff, 0 0 40px red, 0 0 70px red, 0 0 80px red, 0 0 100px red, 0 0 150px red, 0 0 200px red;
  }
  to {
    background-color: #fff;
  }
}
              
            
!

JS

              
                const ledStates = [
  { name: "modeOne",
    state: [ "high-beam", "high-beam", "high-beam", "high-beam"]
  },
  { name: "modeTwo",
    state: [ "low-beam", "low-beam", "low-beam", "low-beam"]
  },
  { name: "modeThree",
    state: [ "high-beam shine", "high-beam shine", "high-beam shine", "high-beam shine"]
  },
  { name: "modeFour",
    state: [ "low-beam alter-two", "low-beam alter-one", "low-beam alter-one", "low-beam alter-two"]
  },
  { name: "modeFive",
    state: [ "low-beam alter-one", "low-beam alter-two", "low-beam alter-two", "low-beam alter-one"]
  }
];

function modeOne(arr) {
  // Remove current state
  const grid = document.querySelector(".grid");
  grid.innerHTML = ``;

  // Read js object for state
  const currentLedStates = ledStates.find((key) => key.name == 'modeOne').state.map((key) => `<div class='${key}'></div>`);
  
  // Create markup
  let markup = ``;
  currentLedStates.map(child => (markup += child));
  grid.innerHTML += markup;

  // Re-enable event listeners
  init();
}

function modeTwo(arr) {
  const grid = document.querySelector(".grid");
  grid.innerHTML = ``;

  // Read js object for state
  const currentLedStates = ledStates.find((key) => key.name == 'modeTwo').state.map((key) => `<div class='${key}'></div>`);
  
  // Create markup
  let markup = ``;
  currentLedStates.map(child => (markup += child));
  grid.innerHTML += markup;

  init();
}

function modeThree(arr) {
  const grid = document.querySelector(".grid");
  grid.innerHTML = ``;

  // Read js object for state
  const currentLedStates = ledStates.find((key) => key.name == 'modeThree').state.map((key) => `<div class='${key}'></div>`);
  
  // Create markup
  let markup = ``;
  currentLedStates.map(child => (markup += child));
  grid.innerHTML += markup;

  init();
}

function modeFour(arr) {
  const grid = document.querySelector(".grid");
  grid.innerHTML = ``;

  // Read js object for state
  const currentLedStates = ledStates.find((key) => key.name == 'modeFour').state.map((key) => `<div class='${key}'></div>`);
  
  // Create markup
  let markup = ``;
  currentLedStates.map(child => (markup += child));
  grid.innerHTML += markup;

  init();
}

function modeFive(arr) {
  const grid = document.querySelector(".grid");
  grid.innerHTML = ``;

  // Read js object for state
  const currentLedStates = ledStates.find((key) => key.name == 'modeFive').state.map((key) => `<div class='${key}'></div>`);
  
  // Create markup
  let markup = ``;
  currentLedStates.map(child => (markup += child));
  grid.innerHTML += markup;

  init();
}

function reset(arr) {
  initialState();
  init();
}

function init() {
  document.getElementById("one").addEventListener("click", modeOne);
  document.getElementById("two").addEventListener("click", modeTwo);
  document.getElementById("three").addEventListener("click", modeThree);
  document.getElementById("four").addEventListener("click", modeFour);
  document.getElementById("five").addEventListener("click", modeFive);
  document.getElementById("reset").addEventListener("click", reset);
}

function initialState() {
  const grid = document.querySelector(".grid");
  grid.innerHTML = ``;

  const innerLED = `<div class="low-beam off"></div>\
      <div class="low-beam off"></div>\
      <div class="low-beam off"></div>\
      <div class="low-beam off"></div>`;
  grid.innerHTML += innerLED;
}

initialState();
init();

              
            
!
999px

Console