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

              
                .info
  span Click, scroll, swipe, or press arrow keys to navigate

.shelf
  img.l4.book(src="https://source.unsplash.com/random/200x450")
  img.l3.book(src="https://source.unsplash.com/random/400x600")
  img.l2.book(src="https://source.unsplash.com/random/450x600")
  img.l1.book(src="https://source.unsplash.com/random/500x600")
  img.c.book(src="https://source.unsplash.com/random/200x400")
  img.r1.book(src="https://source.unsplash.com/random/300x600")
  img.r2.book(src="https://source.unsplash.com/random/400x500")
  img.r3.book(src="https://source.unsplash.com/random/150x400")
  img.r4.book(src="https://source.unsplash.com/random/200x350")
  img.r4.book(src="https://source.unsplash.com/random/100x350")
  img.r4.book(src="https://source.unsplash.com/random/150x350")
  img.r4.book(src="https://source.unsplash.com/random/120x300")
  img.r4.book(src="https://source.unsplash.com/random/400x550")
  img.r4.book(src="https://source.unsplash.com/random/300x550")
.control
  .button.left
  .button.right
              
            
!

CSS

              
                body {
  background: #f0f0f0;
  margin: 0;
  padding: 0;
  height: 100vh;
  width: 100%;
  display: flex;
  transform-style: preserve-3d;
  perspective: 800px;
  overflow: hidden;
  * {
    transition: 300ms;
  }
}

$bounce: cubic-bezier(.17,.67,.83,.67);
$bh: 300px;
$bw: 200px;

.shelf {
  position: relative;
  height: 100%;
  width: 100%;
  transform: translateX(#{($bw * -.65)}) translateY(-20px) translateZ(-80px) rotateX(-6deg) rotateY(-36deg);
}

.shelf, .control {
  display: flex;
  flex-direction: row;
  justify-content: center;
  align-items: center;
  transform-style: preserve-3d;
  perspective: 800px;
}

.control {
  position: absolute;
  bottom: 4%;
  left: 36%;
  transform-style: preserve-3d;
  perspective: 800px;
  transform: translateX(#{($bw * -.65)}) translateY(-20px) translateZ(-80px) rotateX(-6deg) rotateY(-24deg);
  .button {
    position: relative;
    height: 60px;
    width: 60px;
    border: 5px solid #222;
    opacity: 0.5;
    border-radius: 5px;
    cursor: pointer;
    * {
      pointer-events: none;
    }
    &:first-child {
      margin-right: 80px;
    }
    &.left, &.right {
      &:after {
        content: '';
        position: absolute;
        height: 50%;
        width: 50%;
        background-color: #222;
        top: 25%;
        left: 25%;
      }
    }
    &.left:after {
      clip-path: polygon(75% 0, 25% 50%, 75% 100%)
    }
    &.right:after {
      clip-path: polygon(25% 0, 75% 50%, 25% 100%)
    }
    &:hover {
      opacity: 0.9;
      transition: 150ms $bounce;
      transform: scale(1.05);
    }
    &:active,
    &.active {
      border-color: dodgerblue;
      transform: scale(1);
      &, * {
        transition: 50ms $bounce;
      }
      &:after {
        background-color: dodgerblue;
      }
    }
  }
}

.book {
  position: absolute;
  height: $bh;
  width: $bw;
  object-fit: cover;
  overflow: hidden;
  transform: rotateY(-130deg);
  top: calc(50% - #{$bh * .5});
}

$center: 50%;
$offset: 90px;
$opacity-taper: 0.2;
$opacity-end: 0;

.c {
  left: $center;
}
.l1 {
  left: calc(#{$center} - #{$offset});
}
.l2 {
  left: calc(#{$center} - #{$offset * 2});
}
.l3 {
  opacity: $opacity-taper;
  left: calc(#{$center} - #{$offset * 3});
}
.l4 {
  opacity: $opacity-end;
  transform: rotateY(-130deg) scale(0.8);
  left: calc(#{$center} - #{$offset * 4});
}
.r1 {
  left: calc(#{$center} + #{$offset})
}
.r2 {
  left: calc(#{$center} + #{$offset * 2});
}
.r3 {
  opacity: $opacity-taper;
  left: calc(#{$center} + #{$offset * 3});
}
.r4 {
  opacity: $opacity-end;
  transform: rotateY(-130deg) scale(0.8);
  left: calc(#{$center} + #{$offset * 4});
}

.info {
  position: fixed;
  padding: 1em 2.5em;
  opacity: 0.6;
  &:before {
    position: absolute;
    top: 50%;
    left: 1em;
    height: 1rem;
    width: 1rem;
    content: 'i';
    border: 1px solid black;
    border-radius: 50%;
    text-align: center;
    transform: translateY(-50%);
    font-size: 0.9em;
  }
}
              
            
!

JS

              
                var cooldown = new Date();
const cooldownDuration = 50;
const debounceState = {
  left: null,
  right: null,
}

document.addEventListener('DOMContentLoaded', start)

function start(){
  document.querySelector('.button.left').onclick = () => flow(-1)
  document.querySelector('.button.right').onclick = () => flow(1)
  // add scroll listener
  window.addEventListener('wheel', e => {
    if (Math.abs(e.deltaY) > Math.abs(e.deltaX)) {
      flow(e.deltaY)
    } else {
      flow(e.deltaX)
    }
  })
  
  // add touch listener
  const swipeThreshold = 12
  document.querySelector('.shelf').addEventListener('touchstart', e => {
    var start = e.touches[0].clientX
    window.addEventListener('touchmove', touchMove)
    window.addEventListener('touchend touchcancel', touchEnd)
    
    function touchMove(e){
      const next = e.touches[0].clientX
      if (next > start + swipeThreshold) {
        flow(-1)
      } else if (next < start - swipeThreshold) {
        flow(1)
      }
      start = e.touches[0].clientX
    }
    function touchEnd(){
      window.removeEventListener('touchmove', touchMove)
      window.removeEventListener('touchend touchcancel', touchEnd)
    }
  })
}

// add key listener
window.addEventListener('keydown', e => {
  switch(e.keyCode) {
    case 37:
      return animateClick('left', -1);
    case 39:
      return animateClick('right', 1);
    default:
      return;
  }
  
  // this function allows for the UI buttons to accurately
  // convey activity on keypress/hold
  function animateClick(selector, flowValue) {
    var btn = document.querySelector('.button.' + selector);

    // handle debounce
    if (debounceState[selector] !== null) {
      clearTimeout(debounceState[selector]);
      debounceState[selector] = null;
    }
    
    // renew active animation
    btn.classList.add('active');
    debounceState[selector] = setTimeout(() => {
      btn.classList.remove('active');
    }, cooldownDuration + 5);
    
    // init cover flow
    flow(flowValue);
  }
})

function flow(dir){
  // cooldown max 1 scroll per 50ms
  var timestamp = new Date()
  if (timestamp - cooldown > cooldownDuration){
    // reset cooldown
    cooldown = timestamp
    
    var l4,l3,l2,l1,c,r1,r2,r3,r4;
    // new center element
    if (dir < 0) {
      var c = document.querySelector('.l1')
    } else {
      var c = document.querySelector('.r1')
    }
    // bubbling assignment
    if (c) {
      l1 = c.previousSibling;
      r1 = c.nextSibling;
    }
    if (l1) l2 = l1.previousSibling;
    if (l2) l3 = l2.previousSibling;
    if (l3) l4 = l3.previousSibling;
    if (r1) r2 = r1.nextSibling;
    if (r2) r3 = r2.nextSibling;
    if (r3) r4 = r3.nextSibling;
    if (l4) l4.className = "book l4";
    if (l3) l3.className = "book l3";
    if (l2) l2.className = "book l2";
    if (l1) l1.className = "book l1";
    if (c) c.className = "book c";
    if (r1) r1.className = "book r1";
    if (r2) r2.className = "book r2";
    if (r3) r3.className = "book r3";
    if (r4) r4.className = "book r4";
  }
}
              
            
!
999px

Console