123

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.

            
              <h1>DOM-blocking example</h1>

<input id="hardware" type="checkbox" /><label for="hardware">hardware acceleration</label>

<img id="gif" src="https://media.giphy.com/media/46ib09ZL1SdWuREnj3/giphy.gif" alt="space invaders" />

<svg id="invader" xmlns="http://www.w3.org/2000/svg" viewBox="35.4 35.4 195.8 141.8">
  <path d="M70.9 35.4v17.8h17.7V35.4H70.9zm17.7 17.8v17.7H70.9v17.7H53.2V53.2H35.4V124h17.8v17.7h17.7v17.7h17.7v-17.7h88.6v17.7h17.7v-17.7h17.7V124h17.7V53.2h-17.7v35.4h-17.7V70.9h-17.7V53.2h-17.8v17.7H106.3V53.2H88.6zm88.6 0h17.7V35.4h-17.7v17.8zm17.7 106.2v17.8h17.7v-17.8h-17.7zm-124 0H53.2v17.8h17.7v-17.8zm17.7-70.8h17.7v17.7H88.6V88.6zm70.8 0h17.8v17.7h-17.8V88.6z"/>
  <path d="M319 35.4v17.8h17.6V35.4H319zm17.6 17.8v17.7H319v17.7h-17.7v17.7h-17.7V159.4h17.7V124h17.7v35.4h17.7v-17.7H425.2v17.7h17.7V124h17.7v35.4h17.7V106.3h-17.7V88.6H443V70.9h-17.7V53.2h-17.7v17.7h-53.2V53.2h-17.7zm88.6 0h17.7V35.4h-17.7v17.8zm0 106.2h-35.5v17.8h35.5v-17.8zm-88.6 0v17.8h35.5v-17.8h-35.5zm0-70.8h17.7v17.7h-17.7V88.6zm70.9 0h17.7v17.7h-17.7V88.6z"/>
</svg>

<p>number of documents to store:</p>

<label class="block"><input name="docs" type="radio" value="1000" /> 1,000</label>
<label class="block"><input name="docs" type="radio" value="10000" /> 10,000</label>
<label class="block"><input name="docs" type="radio" value="100000" checked /> 100,000</label>

<p>storage type:</p>

<label class="block"><input name="store" type="radio" value="sessionStorage" checked /> sessionStorage</label>
<label class="block"><input name="store" type="radio" value="object" /> object</label>

<p>storage type:</p>

<button id="write">write</button>
<button id="clear">clear</button>

<p id="report"></p>
            
          
!
            
              body {
  font-family: sans-serif;
  margin: 1em;
}

label.block {
  display: block;
}

#gif {
  position: absolute;
  right: 1em;
}

#invader {
  position: absolute;
  display: block;
  width: 200px;
  left: 50%;
  margin-left: -100px;
  animation: move 2s ease-in-out 0s infinite alternate;
}

#hardware:checked ~ #invader {
  animation-name: movehw;
}

#invader path {
  stroke-width: 0;
  fill: #080;
  animation: flash 1s linear 0s infinite alternate;
}

@keyframes move {
  0% { margin-left: -400px; }
  100% { margin-left: 200px; }
}

@keyframes movehw {
  0% { transform: translateX(-300px); }
  100% { transform: translateX(300px); }
}

@keyframes flash {
  0% { opacity: 1; }
  0% { opacity: 0.6; }
}
            
          
!
            
              (() => {

  'use strict';

  // animate invader
  const
    viewX = [35.4, 283.6],
    invader = document.getElementById('invader');

  let frame = 0;

  setInterval(() => {
    frame = ++frame % 2;
    invader.viewBox.baseVal.x = viewX[frame];
  }, 400);


  // write to storage
  let
    storeObject = {},
    report = document.getElementById('report');

  document.getElementById('write').addEventListener('click', e => {

    let
      ts = +new Date(),
      store = document.querySelector('input[name="store"]:checked').value,
      docs = parseInt(document.querySelector('input[name="docs"]:checked').value, 10) || 0;

    for (let i = docs; i; i--) {

      let
        key = `key-${i}`,
        value = JSON.stringify({data: Math.random()});

      switch(store) {

        case 'sessionStorage':
          sessionStorage.setItem(key, value);
          break;

        case 'object':
          storeObject[key] = value;
          break;
      }

    }
    report.textContent = `write took ${+new Date() - ts}ms`;

  });


  // clear storage
  document.getElementById('clear').addEventListener('click', e => {

    let ts = +new Date();
    storeObject = {};
    sessionStorage.clear();
    report.textContent = `clear took ${+new Date() - ts}ms`;

  });

})();
            
          
!
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.

Console