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.

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

            
              <a href="https://youtu.be/B2xYaxIeE7w" target="_blank" data-keyframers-credit style="color: #000"></a>
<script src="https://codepen.io/shshaw/pen/QmZYMG.js"></script>

<div id="app" data-state="playlist">
  <div class="playlist">
    <figure class="song">
      <img src="https://source.unsplash.com/RnCPiXixooY/900x900" alt="" width="900" height="900" />
      <figcaption></figcaption>
    </figure>
    <figure class="song">
      <img src="https://source.unsplash.com/GfmIT_pseDQ/900x900" alt="" width="900" height="900" />
      <figcaption></figcaption>
    </figure>
    <figure class="song">
      <img src="https://source.unsplash.com/sf_1ZDA1YFw/900x900" alt="" width="900" height="900" />
      <figcaption></figcaption>
    </figure>
    <figure class="song">
      <img src="https://source.unsplash.com/kEXMAGTivXA/900x900" alt="" width="900" height="900" />
      <figcaption></figcaption>
    </figure>
    <figure class="song">
      <img src="https://source.unsplash.com/pJ_DCj9KswI/900x900" alt="" width="900" height="900" />
      <figcaption></figcaption>
    </figure>
    <figure class="song">
      <img src="https://source.unsplash.com/gI7zgb80QWY/900x900" alt="" width="900" height="900" />
      <figcaption></figcaption>
    </figure>
  </div>
  
  <div class="screens">
    <div data-screen="genre">
      <ul class="content">
        <li>Singer</li>
        <li data-selected>Chosen</li>
        <li>Radio</li>
      </ul>
    </div>
    <div data-screen="playlist" data-active>
      <div class="content">
        <div class="song-title" data-flip-key="song-title"><strong>Case study 01</strong></div>
        <div class="song-artist" data-flip-key="song-artist">Stephen Shaw</div>
        
        <div class="song-lyrics"></div>
      </div>
    </div>
    <div data-screen="song">
      <div class="content">
        <div class="song-title" data-flip-key="song-title"><strong>Case study 01</strong></div>
        <div class="song-artist" data-flip-key="song-artist">Stephen Shaw</div>
        
        <div class="song-lyrics">
          <p>Lorem ipsum dolor sit amet consectetur adipisicing elit.</p>
          <p> Amet, maiores. </p>
          <p>Temporibus.</p>
          <p> Minus delectus at pariatur eveniet vitae blanditiis excepturi cum dicta, aliquid repellat esse hic laudantium alias et. </p>
          <p>Molestiae?</p>
        </div>
      </div>
    </div>
    
    
    <nav class="screen-nav">
      <ol class="screen-nav-list">
        <li class="screen-nav-dot" data-screen="genre"></li>
        <li class="screen-nav-dot" data-screen="playlist"></li>
        <li class="screen-nav-dot" data-screen="song"></li>
      </ol>
    </nav>
  </div>
  
</div>
            
          
!

CSS

            
              @import url('https://fonts.googleapis.com/css?family=Lato:400,700&display=swap');

*, *:before, *:after {
  box-sizing: border-box;
  position: relative;
  --duration: .6s;
  --ease: cubic-bezier(.5,0,.2,1);
}

html, body {
  font-family: Lato, sans-serif;
  height: 100%;
  width: 100%;
  margin: 0;
  padding: 0;
  background: #eee;
  font-size: 12px;
}

body {
  display: flex;
  justify-content: center;
  align-items: center;
}

#app {
  --dx-px: calc(var(--dx, 0) * 1px);
  --dx-py: calc(var(--dy) * 1px);

  height: 90vmin;
  width: 50vmin;
  border: 2px solid black;
  border-radius: 5vmin;
  overflow: hidden;
  font-size: 2.5vmin;
  background: #fff;
  box-shadow: 0 2em 4em rgba(0,0,0,.3);

  &:before {
    position: absolute;
    width: 100%;
    text-align: center;
    top: .5em;
    right: .5em;
    background: #FFF;
    content: attr(data-state);
    padding: .25em .5em;
    font-family: monospace;
    transform: translateX(calc(var(--dx-px) * 0.2));
    transition: transform .6s ease;
    transition-duration: calc(var(--idle, 0) * .6s);
  }
}

.playlist {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template: 1 / 1;
  z-index: 10;
  transition: transform var(--duration) var(--ease);

  .song {
    grid-area: 1 / 1; 
    margin: auto;
  }
}

.screens {
  pointer-events: none;
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;

  > [data-screen] {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%; // shaw fix this sorry lol
    
  z-index: 50;
  }
}

[data-screen] {
  visibility: hidden;
  display: grid;
  padding: 0 2vmin;
  grid-template-columns: 50% 50%;

  &[data-active] {
    visibility: visible;
  }

  > .content {
    grid-area: content;
    align-self: center;
    padding: 1em;
    transition: transform var(--duration) var(--ease);
  }
}

[data-screen="genre"] {
  grid-template-areas: 'content songs';

  > .content {
    transform: translateX(-100%);
    padding: 0;
    margin: 0;
    margin-left: .5rem;
    
    li {
      list-style: none;
      margin: 3rem 0;
      display: flex;
      justify-content: flex-start;
      align-items: center;
      opacity: 0.4;
      font-weight: bold;
      
      &[data-selected] {   
        opacity: 1;
        &:after {
          content: '';
          height: 6px;
          width: 6px;
          border-radius: 6px;
          background: #e00;
          display: inline-block;
          margin-left: .5rem;
        }
      }
    }
  }

  [data-state="genre"] & > .content {
    transform: none;
  }
}

[data-screen="playlist"] {
  grid-template-areas: 'songs content'
}

[data-screen="song"] {
  grid-template-areas: 'songs content'
}


/* ---------------------------------- */


.song {
  margin: 0;

  --percentage: calc( var(--index) / var(--length) );
  --offset: calc( var(--index) - var(--song) );

  z-index: calc( var(--offset) * 1 );
  transition: z-index var(--duration) var(--ease), transform var(--duration) var(--ease);

  img {
    pointer-events: none;
    display: block; 
    max-width: 50%; 
    height: auto; 
    transition: 
      transform var(--duration) var(--ease),
      transform-origin var(--duration) var(--ease),
      z-index var(--duration) linear;
    transform: none;
    transform-origin: -100% center;
    border-radius: 5%;
  } 


  &[data-selected] {
    z-index: calc( var(--length) * 2 );
    opacity: 1;

    img { transform: none; }

    ~ .song { 
      z-index: calc( var(--length) - var(--offset) * 1 );
    }
  }

}

/* ---------------------------------- */

// Prevent panning from affecting songs
[data-panning] {
  .song, .song > *, .content {
    transition: none;
    pointer-events: none;
  }
}

[data-state="genre"] {
  .playlist {
    transform: translateX(50%); 
  }

  .song {    
    z-index: calc(var(--length) - var(--index)) !important;

    img {
      transform: scale( 
        calc(1 - (.3 * (var(--percentage) )) ) 
      );  
    }
  }

  &[data-panning] {

    .content {
      transform: translateX(calc(var(--dx) * .1px));
    }

    .song {
      transform: translateX(calc(var(--dx) * .2px));
    }
  }
}

[data-state="playlist"] {

  .playlist {
    transform: none; 
  }

  .song  {
    img {
      transform: rotate( calc(25deg * var(--offset)) ); 
    }
  }

  &[data-panning] {
    &[data-panning="right"] {
      .content {
        transform: translateX(calc(var(--dx) * .3px));
        opacity: calc((100 - var(--dx)) / 100);
      }
    }

    .song {
      transform:
        translateX(calc(var(--dx) * .2px));

      img {
        transform: rotate( 
          calc(
            25deg * var(--offset) + 
            (10deg * var(--offset) * (var(--dx) / 400))
          )
        )

          rotate(
            calc(
              (25deg * (var(--dy) / 600)) 
            )
          ); 
      }
    }
  }

  &[data-panning="right"] {
    .song {
      img {
        transform: rotate( 
          calc(
            25deg * var(--offset) + 
            (-25deg * var(--offset) * (var(--dx) / 200))
          )
        ); 
      }
    }
  }

}

.song-lyrics {
  opacity: 0;
  transform: translateY(100%);
  transition: all var(--duration) var(--ease);
}

[data-state="song"] {

  .song-lyrics {
    opacity: 1;
    transform: translateY(0);
  }

  .song {
    img {
      transform: 
        translate( 
          -20%, 
          calc(40% * var(--offset))
        ); 
    }

    &[data-selected] {
      img { transform: none; }
    }
  }

  &[data-panning="right"] {

    .song {
      transform:
        translateX(calc(var(--dx) * .2px))
        translateY(calc(var(--dy) * .2px));

      img {
        transform: 
          translate( 
            -20%, 
            calc(40% * var(--offset))
          ) 
          rotate( 
            calc(
              (15deg * var(--offset) * (var(--dx) / 200))
            ) 
          ); 

      }
    }
  }
}

.song-title {
  text-transform: uppercase;
  white-space: nowrap;
  margin-bottom: 1rem;
}

.song-artist {
  font-size: 80%;
  letter-spacing: 1px;
}

.song-lyrics {
  font-size: 80%;
  > p {
    line-height: 1rem;
    opacity: 0.6;
   
    &:first-child {
      opacity: 1;
    }
  }
}

/* ---------------------------------- */

.screen-nav {
  position: absolute;
  top: 4rem;
  left: 2rem;
  font-size: .6rem;
  z-index: 999;
}

.screen-nav-list,
.screen-nav-dot {
  margin: 0;
  padding: 0;
  list-style-type: none;
}

.screen-nav-list {
  contain: layout;
  display: flex;
}

.screen-nav-dot {
  display: block;
  width: 1em;
  height: 1em;
  margin-right: .5em;
  border-radius: .5em;
  visibility: visible;
  background: #bbb;
  transition: 
    background-color var(--duration) linear,
    width var(--duration) var(--ease);
  
  &[data-active] {
    background: #e00;
    width: 3em;
  }
}

/* ---------------------------------- */


// See https://youtu.be/PDSWq6WaJMk
:root {
  --mouse-x: calc(50vw + 1px);
  --mouse-y: calc(50vh + 1px);
  cursor: crosshair;
}

.mouse-tracker {
  z-index: 999;
  position: fixed;
  top: 0;
  left: 0;
  width: 5vmin;
  height: 5vmin;
  background: rgba(255,255,255,.2);
  border-radius: 50%;
  border: solid 2px #000;
  opacity: 0.8;
  transform: 
    translate(-50%, -50%)
    translate(
      var(--mouse-x),
      var(--mouse-y)
    )
    scale( calc( 1 - (var(--mouse-down) * .2)) );
  pointer-events: none;
  transition: transform .1s ease;
}


            
          
!

JS

            
              console.clear();
const elApp = document.querySelector('#app');
const elScreens = Array.from(document.querySelectorAll('[data-screen]'));

const elSongs = Array.from(document.querySelectorAll('.song'));
console.log(elSongs);
let currentSong = 2;

const flipping = new Flipping({
  duration: 600,
  activeSelector: el => {
    return el.matches('[data-active] *')
  }
});

function setCurrentSong(i) {
  elSongs.forEach( song => {
    delete song.dataset.selected;
  });

  currentSong = i;
  elApp.style.setProperty('--song', currentSong);
  elSongs[currentSong].dataset.selected = true;
}

setCurrentSong(currentSong);

const machine = {
  initial: 'playlist',
  states: {
    genre: {
      on: {
        panleft: 'playlist'
      }
    },
    playlist: {
      on: {
        panleft: 'song',
        panright: 'genre',
        pandown: () => {
          if (currentSong > 0) {
            setCurrentSong(currentSong - 1)
          }
        },
        panup: () => {
          if (currentSong < elSongs.length - 1) {
            setCurrentSong(currentSong + 1)
          }
        }
      }
    },
    song: {
      on: {
        panright: 'playlist',
        pandown: () => {
          if (currentSong > 0) {
            setCurrentSong(currentSong - 1)
          }
        },
        panup: () => {
          if (currentSong < elSongs.length - 1) {
            setCurrentSong(currentSong + 1)
          }
        }
      }
    }
  }
}


let currentState = machine.initial; // 'genre'

function transition(state, event) {
  console.log(event);
  const t = machine.states[state]
  .on[event];

  if (typeof t === 'function') {
    return t(event) || state;
  }

  return t || state;
}


/* ---------------------------------- */

const hApp = new Hammer(elApp, {
  direction: Hammer.DIRECTION_ALL,
  threshold: 2,
});

hApp.get('pan')
  .set({ direction: Hammer.DIRECTION_ALL });


let lastDirection;
hApp.on('panleft panright panup pandown', event => {
  // is this the hokey pokey
  lastDirection = event.type;
});

hApp.on('panstart panleft panright panup pandown', event => {
  //console.log(event.type, event.center, event);
  elApp.style.setProperty('--idle', 0);
  elApp.style.setProperty('--dx', event.deltaX);
  elApp.style.setProperty('--dy', event.deltaY);
  elApp.dataset.panning = event.type.replace('pan','');
});

hApp.on('panend', flipping.wrap(event => {
  elApp.style.setProperty('--idle', 1);
  elApp.style.setProperty('--dx', 0);
  elApp.style.setProperty('--dy', 0);
  delete elApp.dataset.panning;
  
  if (event.distance < 50) {
    // too small of a movement!
    return;
  }
  
  updateState(lastDirection);
  
}))

function updateState(event){
  currentState = transition(currentState, event);
  
  elApp.dataset.state = currentState;
  
  elScreens.forEach(elScreen => {
    if (elScreen.dataset.screen === currentState) {
      elScreen.dataset.active = true;
    } else {
      delete elScreen.dataset.active;
    }
  });
}

updateState();

/* ---------------------------------- */

// Index all of the songs with CSS variables
elApp.style.setProperty('--length', elSongs.length - 1);

elSongs.forEach( (song,i) => {
  song.style.setProperty('--index', i);

  song.addEventListener('click', ()=>{
    setCurrentSong(i);
  });
});



// See https://youtu.be/PDSWq6WaJMk
document.body.insertAdjacentHTML('beforeend','<div class="mouse-tracker"></div>');
document.addEventListener("mousemove", e => {
  document.documentElement.style.setProperty("--mouse-x", e.clientX +'px');
  document.documentElement.style.setProperty("--mouse-y", e.clientY +'px');
});
document.addEventListener("mousedown", e => {
  document.documentElement.style.setProperty("--mouse-down", 1);
});
document.addEventListener("mouseup", e => {
  document.documentElement.style.setProperty("--mouse-down", 0);
});

            
          
!
999px

Console