Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ 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

              
                <div class="table">
  <div class="table__river river">
    <div class="river__placeholder">
      <div class="card card--placeholder"></div>
      <div class="card card--placeholder"></div>
      <div class="card card--placeholder"></div>
      <div class="card card--placeholder"></div>
      <div class="card card--placeholder"></div>
    </div>
    <div class="river__cards">
      <button class="card">
        <div class="card__side card__side--front">
          <img src="https://assets.codepen.io/605876/card_hearts_J.png" width="40" height="58" />
        </div>
        <div class="card__side card__side--back">
          <img src="https://assets.codepen.io/605876/card_back.png" width="40" height="58" />
        </div>
      </button>
      <button class="card">
        <div class="card__side card__side--front">
          <img src="https://assets.codepen.io/605876/card_hearts_Q.png" width="40" height="58" />
        </div>
        <div class="card__side card__side--back">
          <img src="https://assets.codepen.io/605876/card_back.png" width="40" height="58" />
        </div>
      </button>
      <button class="card">
        <div class="card__side card__side--front">
          <img src="https://assets.codepen.io/605876/card_hearts_K.png" width="40" height="58" />
        </div>
        <div class="card__side card__side--back">
          <img src="https://assets.codepen.io/605876/card_back.png" width="40" height="58" />
        </div>
      </button>
      <button class="card">
        <div class="card__side card__side--front">
          <img src="https://assets.codepen.io/605876/card_hearts_A.png" width="40" height="58" />
        </div>
        <div class="card__side card__side--back">
          <img src="https://assets.codepen.io/605876/card_back.png" width="40" height="58" />
        </div>
      </button>
      <button class="card">
        <div class="card__side card__side--front">
          <img src="https://assets.codepen.io/605876/card_joker_red.png" width="40" height="58" />
        </div>
        <div class="card__side card__side--back">
          <img src="https://assets.codepen.io/605876/card_back.png" width="40" height="58" />
        </div>
      </button>
    </div>
  </div>
  <div class="table__shuffler shuffler">
    <div class="shuffler__controls">
      <button class="shuffle-button">Shuffle</button>
      <div class="control-group">
        <label for="count">No. of shuffles</label>
        <input id="count" type="range" class="count" min="1" max="10" step="1">
      </div>
    </div>
    <div class="shuffler__placeholder">
      <div class="card card--placeholder"></div>
      <div class="card card--placeholder"></div>
      <div class="card card--placeholder"></div>
      <div class="card card--placeholder"></div>
      <div class="card card--placeholder"></div>
    </div>
    <div class="shuffler__cards"></div>
  </div>
</div>
              
            
!

CSS

              
                :root {
  --card-width: max(8vmin, 80px);
  --card-outline: calc(var(--card-width) * 0.05);
  --card-gap: calc(var(--card-width) * 0.1);
  --table-color: hsl(350 70% 40%);
  --table-outline: hsl(0 0% 92% / 0.6);
}

* {
  box-sizing: border-box;
  touch-action: none;
}

body {
  display: grid;
  place-items: center;
  min-height: 100vh;
  text-align: center;
  background: var(--table-color);
  font-family: "Google Sans", sans-serif, system-ui;
}

.shuffle-button {
  transition: transform 0.1s;
  transform: translateY(var(--y, 0)) scale(var(--scale, 1));
  background: hsl(350 80% 30%);
  border: 2px solid white;
  padding: 8px 16px;
  color: white;
  font-weight: bold;
}

.shuffle-button:hover {
  --y: -10%;
  --scale: 1.1;
}

.shuffle-button:active {
  --y: 5%;
  --scale: 0.9;
}

label {
  color: hsl(0 0% 100%);
}

[type="range"] {
  accent-color: hsl(215 50% 85%);
}

.shuffler__controls {
  display: flex;
  flex-direction: column;
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.control-group {
  position: absolute;
  top: calc(100% + 1rem);
  left: 50%;
  transform: translate(-50%);
}

.shuffler__placeholder,
.card--placeholder {
  pointer-events: none;
}

img {
  height: 100%;
  width: 100%;
}

.river__cards {
  display: grid;
  position: absolute;
  grid-auto-flow: column;
  gap: var(--card-gap);
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

button {
  cursor: pointer;
}

[aria-pressed="true"] {
  --rotate: 180deg;
}

.card {
  transform-style: preserve-3d;
  transform: rotateY(var(--rotate, 0deg));
  appearance: none;
  border: 0;
  width: var(--card-width);
  aspect-ratio: 40 / 58;
  contain: paint;
  order: var(--order);
  position: relative;
}

.card__side {
  position: absolute;
  inset: 0;
  backface-visibility: hidden;
}

.card__side--back {
  transform: rotateY(180deg);
}

.table .table__shuffler {
  position: relative;
  margin-top: 10vmin;
  padding: calc(var(--card-width) * 0.25) calc(var(--card-width) * 0.5);
  border-radius: var(--card-gap);
  border: var(--card-outline) solid var(--table-outline);
  display: inline-flex;
}

.shuffler__placeholder {
  display: inline-grid;
  grid-template-columns: repeat(5, calc(var(--card-width) * 0.5));
  place-items: center;
}

.shuffler__cards {
  place-items: center;
  display: inline-grid;
  grid-template-columns: repeat(5, calc(var(--card-width) * 0.5));
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}

.shuffler__cards .card {
  --rotate: 180deg;
}

.river {
  border-radius: var(--card-gap);
  position: relative;
  padding: calc(var(--card-width) * 0.5);
  border: var(--card-outline) solid var(--table-outline);
}

.river__placeholder {
  display: flex;
  gap: var(--card-gap);
  z-index: -1;
}

.river__placeholder .card {
  background: transparent;
  border: var(--card-outline) solid var(--table-outline);
}

::page-transition-container(transport-card-in-0),
::page-transition-outgoing-image(transport-card-in-0),
::page-transition-incoming-image(transport-card-in-0) {
  animation-duration: 0.1s;
  animation-delay: 0s;
}
::page-transition-image-wrapper(transport-card-in-0) {
  mix-blend-mode: normal;
}
::page-transition-incoming-image(transport-card-in-0),
::page-transition-outgoing-image(transport-card-in-0) {
  height: 100%;
}
::page-transition-container(transport-card-in-1),
::page-transition-outgoing-image(transport-card-in-1),
::page-transition-incoming-image(transport-card-in-1) {
  animation-duration: 0.1s;
  animation-delay: 0.1s;
}
::page-transition-image-wrapper(transport-card-in-1) {
  mix-blend-mode: normal;
}
::page-transition-incoming-image(transport-card-in-1),
::page-transition-outgoing-image(transport-card-in-1) {
  height: 100%;
}
::page-transition-container(transport-card-in-2),
::page-transition-outgoing-image(transport-card-in-2),
::page-transition-incoming-image(transport-card-in-2) {
  animation-duration: 0.1s;
  animation-delay: 0.2s;
}
::page-transition-image-wrapper(transport-card-in-2) {
  mix-blend-mode: normal;
}
::page-transition-incoming-image(transport-card-in-2),
::page-transition-outgoing-image(transport-card-in-2) {
  height: 100%;
}
::page-transition-container(transport-card-in-3),
::page-transition-outgoing-image(transport-card-in-3),
::page-transition-incoming-image(transport-card-in-3) {
  animation-duration: 0.1s;
  animation-delay: 0.30000000000000004s;
}
::page-transition-image-wrapper(transport-card-in-3) {
  mix-blend-mode: normal;
}
::page-transition-incoming-image(transport-card-in-3),
::page-transition-outgoing-image(transport-card-in-3) {
  height: 100%;
}
::page-transition-container(transport-card-in-4),
::page-transition-outgoing-image(transport-card-in-4),
::page-transition-incoming-image(transport-card-in-4) {
  animation-duration: 0.1s;
  animation-delay: 0.4s;
}
::page-transition-image-wrapper(transport-card-in-4) {
  mix-blend-mode: normal;
}
::page-transition-incoming-image(transport-card-in-4),
::page-transition-outgoing-image(transport-card-in-4) {
  height: 100%;
}
::page-transition-container(transport-card-out-0),
::page-transition-outgoing-image(transport-card-out-0),
::page-transition-incoming-image(transport-card-out-0) {
  animation-duration: 0.1s;
  animation-delay: 0.5s;
}
::page-transition-image-wrapper(transport-card-out-0) {
  mix-blend-mode: normal;
}
::page-transition-incoming-image(transport-card-out-0),
::page-transition-outgoing-image(transport-card-out-0) {
  height: 100%;
}
::page-transition-container(transport-card-out-1),
::page-transition-outgoing-image(transport-card-out-1),
::page-transition-incoming-image(transport-card-out-1) {
  animation-duration: 0.1s;
  animation-delay: 0.6s;
}
::page-transition-image-wrapper(transport-card-out-1) {
  mix-blend-mode: normal;
}
::page-transition-incoming-image(transport-card-out-1),
::page-transition-outgoing-image(transport-card-out-1) {
  height: 100%;
}
::page-transition-container(transport-card-out-2),
::page-transition-outgoing-image(transport-card-out-2),
::page-transition-incoming-image(transport-card-out-2) {
  animation-duration: 0.1s;
  animation-delay: 0.7s;
}
::page-transition-image-wrapper(transport-card-out-2) {
  mix-blend-mode: normal;
}
::page-transition-incoming-image(transport-card-out-2),
::page-transition-outgoing-image(transport-card-out-2) {
  height: 100%;
}
::page-transition-container(transport-card-out-3),
::page-transition-outgoing-image(transport-card-out-3),
::page-transition-incoming-image(transport-card-out-3) {
  animation-duration: 0.1s;
  animation-delay: 0.8s;
}
::page-transition-image-wrapper(transport-card-out-3) {
  mix-blend-mode: normal;
}
::page-transition-incoming-image(transport-card-out-3),
::page-transition-outgoing-image(transport-card-out-3) {
  height: 100%;
}
::page-transition-container(transport-card-out-4),
::page-transition-outgoing-image(transport-card-out-4),
::page-transition-incoming-image(transport-card-out-4) {
  animation-duration: 0.1s;
  animation-delay: 0.9s;
}
::page-transition-image-wrapper(transport-card-out-4) {
  mix-blend-mode: normal;
}
::page-transition-incoming-image(transport-card-out-4),
::page-transition-outgoing-image(transport-card-out-4) {
  height: 100%;
}
::page-transition-container(initial-shuffle-card-0),
::page-transition-outgoing-image(initial-shuffle-card-0),
::page-transition-incoming-image(initial-shuffle-card-0) {
  animation-duration: 0.1s;
  animation-delay: 0.5s;
}
::page-transition-image-wrapper(initial-shuffle-card-0) {
  mix-blend-mode: normal;
}
::page-transition-incoming-image(initial-shuffle-card-0),
::page-transition-outgoing-image(initial-shuffle-card-0) {
  height: 100%;
}
::page-transition-container(initial-shuffle-card-1),
::page-transition-outgoing-image(initial-shuffle-card-1),
::page-transition-incoming-image(initial-shuffle-card-1) {
  animation-duration: 0.1s;
  animation-delay: 0.6s;
}
::page-transition-image-wrapper(initial-shuffle-card-1) {
  mix-blend-mode: normal;
}
::page-transition-incoming-image(initial-shuffle-card-1),
::page-transition-outgoing-image(initial-shuffle-card-1) {
  height: 100%;
}
::page-transition-container(initial-shuffle-card-2),
::page-transition-outgoing-image(initial-shuffle-card-2),
::page-transition-incoming-image(initial-shuffle-card-2) {
  animation-duration: 0.1s;
  animation-delay: 0.7s;
}
::page-transition-image-wrapper(initial-shuffle-card-2) {
  mix-blend-mode: normal;
}
::page-transition-incoming-image(initial-shuffle-card-2),
::page-transition-outgoing-image(initial-shuffle-card-2) {
  height: 100%;
}
::page-transition-container(initial-shuffle-card-3),
::page-transition-outgoing-image(initial-shuffle-card-3),
::page-transition-incoming-image(initial-shuffle-card-3) {
  animation-duration: 0.1s;
  animation-delay: 0.8s;
}
::page-transition-image-wrapper(initial-shuffle-card-3) {
  mix-blend-mode: normal;
}
::page-transition-incoming-image(initial-shuffle-card-3),
::page-transition-outgoing-image(initial-shuffle-card-3) {
  height: 100%;
}
::page-transition-container(initial-shuffle-card-4),
::page-transition-outgoing-image(initial-shuffle-card-4),
::page-transition-incoming-image(initial-shuffle-card-4) {
  animation-duration: 0.1s;
  animation-delay: 0.9s;
}
::page-transition-image-wrapper(initial-shuffle-card-4) {
  mix-blend-mode: normal;
}
::page-transition-incoming-image(initial-shuffle-card-4),
::page-transition-outgoing-image(initial-shuffle-card-4) {
  height: 100%;
}
::page-transition-container(shuffle-card-0),
::page-transition-outgoing-image(shuffle-card-0),
::page-transition-incoming-image(shuffle-card-0) {
  animation-duration: 0.1s;
  animation-delay: 0s;
}
::page-transition-image-wrapper(shuffle-card-0) {
  mix-blend-mode: normal;
}
::page-transition-incoming-image(shuffle-card-0),
::page-transition-outgoing-image(shuffle-card-0) {
  height: 100%;
}
::page-transition-container(shuffle-card-1),
::page-transition-outgoing-image(shuffle-card-1),
::page-transition-incoming-image(shuffle-card-1) {
  animation-duration: 0.1s;
  animation-delay: 0.1s;
}
::page-transition-image-wrapper(shuffle-card-1) {
  mix-blend-mode: normal;
}
::page-transition-incoming-image(shuffle-card-1),
::page-transition-outgoing-image(shuffle-card-1) {
  height: 100%;
}
::page-transition-container(shuffle-card-2),
::page-transition-outgoing-image(shuffle-card-2),
::page-transition-incoming-image(shuffle-card-2) {
  animation-duration: 0.1s;
  animation-delay: 0.2s;
}
::page-transition-image-wrapper(shuffle-card-2) {
  mix-blend-mode: normal;
}
::page-transition-incoming-image(shuffle-card-2),
::page-transition-outgoing-image(shuffle-card-2) {
  height: 100%;
}
::page-transition-container(shuffle-card-3),
::page-transition-outgoing-image(shuffle-card-3),
::page-transition-incoming-image(shuffle-card-3) {
  animation-duration: 0.1s;
  animation-delay: 0.30000000000000004s;
}
::page-transition-image-wrapper(shuffle-card-3) {
  mix-blend-mode: normal;
}
::page-transition-incoming-image(shuffle-card-3),
::page-transition-outgoing-image(shuffle-card-3) {
  height: 100%;
}
::page-transition-container(shuffle-card-4),
::page-transition-outgoing-image(shuffle-card-4),
::page-transition-incoming-image(shuffle-card-4) {
  animation-duration: 0.1s;
  animation-delay: 0.4s;
}
::page-transition-image-wrapper(shuffle-card-4) {
  mix-blend-mode: normal;
}
::page-transition-incoming-image(shuffle-card-4),
::page-transition-outgoing-image(shuffle-card-4) {
  height: 100%;
}

              
            
!

JS

              
                const HEAD = document.querySelector('head')

const ADD_PAGE_TRANSITION_SPEED = (id, speed, delay = '0s') => {
  const PAGE_TRANSITION_STUFF = document.createElement('style')
  PAGE_TRANSITION_STUFF.setAttribute('type', 'text/css')
  PAGE_TRANSITION_STUFF.innerText = `::page-transition-container(${id}),::page-transition-outgoing-image(${id}),::page-transition-incoming-image(${id}) {animation-duration: ${speed}; animation-delay: ${delay};}`
  PAGE_TRANSITION_STUFF.innerText += `::page-transition-image-wrapper(${id}) {mix-blend-mode: normal;}`
  PAGE_TRANSITION_STUFF.innerText += `::page-transition-incoming-image(${id}),:page-transition-outgoing-image(${id}) {height: 100%;}`
  HEAD.appendChild(PAGE_TRANSITION_STUFF)
}

let visualOrder = [0, 1, 2, 3, 4] // Used for tracking the visual order in the DOM
const TRANSPORT_DELAY = 0.25
const TRANSITION_STEP = 0.1
const SHUFFLER = document.querySelector('.shuffle-button')
const CONTROLS = document.querySelector('.shuffler__controls')
const COUNT = document.querySelector('[type="range"]')
const SHUFFLE_AREA = document.querySelector('.shuffler__cards')
const RIVER = document.querySelector('.river__cards')
const CARDS = document.querySelectorAll('.card:not(.card--placeholder)')

COUNT.value = Math.floor(Math.random() * 11)

const generateTransitions = (tag, delay) => {
  for (let c = 0; c < CARDS.length; c++) {
    ADD_PAGE_TRANSITION_SPEED(`${tag}-${c}`, `${TRANSITION_STEP}s`, `${delay + (TRANSITION_STEP * c)}s`)
  }
}
// ADD_PAGE_TRANSITION_SPEED('shuffler', '0.1s', '0s')
// Based on "visual" ordering, set the transition tags
const setTransitionTags = (tag) => {
  visualOrder.forEach((cardIndex, index) => {
    CARDS[index].style.setProperty(
      'page-transition-tag',
      `${tag}-${cardIndex}`
    )
  })
}

const shuffle = () => {
  const POSITIONS = [0, 1, 2, 3, 4].sort(() => Math.random() - 0.5)
  visualOrder = POSITIONS
  CARDS.forEach((card, index) => {
    card.style.setProperty('--order', POSITIONS[index])
  })
}

// Generate the different transition tags
generateTransitions('transport-card-in', 0)
generateTransitions('transport-card-out', 0.5)
generateTransitions('initial-shuffle-card', 0.5)
generateTransitions('shuffle-card', 0)

SHUFFLER.addEventListener('click', async () => {
  // Hide the controls
  CONTROLS.style.display = 'none'
  // Interesting that you can't create them in a stack.
  // Only create them when needed. Makes sense.
  const transportInAction = () => {
    CARDS.forEach((card, index) => {
      SHUFFLE_AREA.appendChild(card)
    })
  }
  const shuffleAction = () => {
    shuffle()
  }
  const transportOutAction = () => {
    CARDS.forEach((card) => {
      RIVER.appendChild(card)
    })
  }
  // 1. Move cards to the shuffler

  const transportInTransition = document.createDocumentTransition()
  // Set the transition tags
  setTransitionTags('transport-card-in')
  await transportInTransition.start(transportInAction)
  // 2. Shuffle the cards
  // Wait one second
  const initialShuffleTransition = document.createDocumentTransition()
  setTransitionTags('initial-shuffle-card')
  await initialShuffleTransition.start(shuffleAction)
  // Arbritrary amount of shuffles
  for (let s = 0; s < COUNT.value; s++) {
    // do a shuffle
    const shuffleTransition = document.createDocumentTransition()
    setTransitionTags('shuffle-card')
    await shuffleTransition.start(shuffleAction)
  }
  // 3. Move cards back to the river
  const transportOutTransition = document.createDocumentTransition()
  setTransitionTags('transport-card-out')
  await transportOutTransition.start(transportOutAction)
  // Reveal the controls
  CONTROLS.style.display = 'block'
})

              
            
!
999px

Console