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.

              <p class="desc">A Virtual Stack Made Of Two Queues</p>

<div class="btn-group">
  <button class="btn push">Push</button>
  <button class="btn pop">Pop</button>

<div class="queues">
  <div class="queue queue1"></div>
  <div class="queue queue2"></div>
<div class="stack-result"></div>
              body {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  width: 100vw;
  height: 100vh;
  background: #573F52;

.desc {
  color: #F4F7F5;
  margin-bottom: 6vh;

.queues {
  position: relative;
  width: 100%;
  height: 30vh;
  margin-bottom: 10vh;

.btn-group {
  width: 100%;
  text-align: center;
  margin-bottom: 6vh;

.btn {
  font-size: 1.1em;
  margin: 0 5px;

.stack-result {
  display: flex;
  width: 100%;
  height: 30vh;

.queue {
  display: flex;
  flex-direction: row-reverse;
  position: absolute;
  top: 0;
  left: 0;
  width: 30vw;
  height: 30vh;
  border-top: 5px #000 solid;
  border-bottom: 5px #000 solid;
  transition: transform 0.4s;

.queue1 {
  border-color: #D86137;
  transform: translate3d(15vw, 0, 0);

.queue2 {
  border-color: #3FAB9B;
  transform: translate3d(55vw, 0, 0);

.item {
  width: 5vw;
  height: 30vh;
  text-align: center;
  vertical-align: middle;
  line-height: 30vh;
  color: #fff;
              const colors = ['#394c82', '#4f3a2b', '#8e725e', '#2c4f34', '#7e8b8c', '#26ad5e', '#8eaf21', '#8d43ad', '#662520', '#16a085', '#d35400', '#d35b9d', '#4f2a4f', '#5b47a3', '#bf382a', '#2880ba', '#346272', '#d85458', '#ffaa00']
let iColor = 0

let iItem = 1
let isPoping = false

const $queues = [

const $push = document.querySelector('.push')
const $pop = document.querySelector('.pop')
const $stackResult = document.querySelector('.stack-result')

$push.addEventListener('click', pushItem)
$pop.addEventListener('click', popItem)

function pushItem () {
  const $item = document.createElement('div')
  $item.className = 'item'
  $item.style.backgroundColor = colors[(iColor++) % colors.length]
  $item.textContent = `${iItem++}`

  // max 6 for demonstration purpose
  if ($queues[0].children.length >= 6) { $push.disabled = true }

async function popItem () {
  if ($queues[0].children.length <= 0 || isPoping) { return }
  isPoping = true

  while($queues[0].children.length > 1) {
    // queue1 dequeue
    await delay(() => {
      const $item = $queues[0].firstElementChild
  // stack pop result
  await delay(() => {
    const $item = $queues[0].firstElementChild
  // switch queue
  await delay(() => {
    $queues[0].style.transform = 'translate3d(55vw, 0, 0)'
    $queues[1].style.transform = 'translate3d(15vw, 0, 0)'
    let t = $queues[0]
    $queues[0] = $queues[1]
    $queues[1] = t

  isPoping = false
  $push.disabled = false

function delay (fn) {
  return new Promise(r => {
    setTimeout(() => {
    }, 800)
🕑 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.