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

              
                <input type="checkbox" id="debug" />

<ul class="cards" id="cards">
    <li id="card_0">
        <img src="https://assets.codepen.io/89905/coverflow--Front-1024x1024.jpg" width="1200" height="1200" />
    </li>
    <li id="card_1">
        <img src="https://assets.codepen.io/89905/coverflow--A-Thousand-Clouds-Front-Cover-1024x1024.jpg" width="1200" height="1200" />
    </li>
    <li id="card_2">
        <img src="https://assets.codepen.io/89905/coverflow--Odd-World-EP-SMALL-1024x1024.png" width="1200" height="1200" />
    </li>
    <li id="card_3">
        <img src="https://assets.codepen.io/89905/coverflow--Forest-Blue-Pre-LR-1024x1024.png" width="1200" height="1200" />
    </li>
    <li id="card_4">
        <img src="https://assets.codepen.io/89905/coverflow--MOM-Remixes-1024x1024.jpg" width="1200" height="1200" />
    </li>
    <li id="card_5">
        <img src="https://assets.codepen.io/89905/coverflow--ALONE-TOGETHER-remix-V71-550x550.jpg" width="1200" height="1200" />
    </li>
    <li id="card_6">
        <img src="https://assets.codepen.io/89905/coverflow--Nature-Therapy-Pre-LR-550x550.png" width="1200" height="1200" />
    </li>
    <li id="card_7">
        <img src="https://assets.codepen.io/89905/coverflow--Deep-Dive-Ambient-Edits-V8-550x550.jpg" width="1200" height="1200" />
    </li>
    <li id="card_8">
        <img src="https://assets.codepen.io/89905/coverflow--Alpine-Koresma-x-Aroth-Artwork-550x550.jpg" width="1200" height="1200" />
    </li>
    <li id="card_9">
        <img src="https://assets.codepen.io/89905/coverflow--Out-Of-the-Dark-Cover-550x550.jpg" width="1200" height="1200" />
    </li>
    <li id="card_11">
        <img src="https://assets.codepen.io/89905/coverflow--2020-06-07-Marley-Carroll-Single-Blue-550x550.jpg" width="1200" height="1200" />
    </li>
    <li id="card_12">
        <img src="https://assets.codepen.io/89905/coverflow--Deep-Dive-EP-Cover-550x550.jpg" width="1200" height="1200" />
    </li>
    <li id="card_13">
        <img src="https://assets.codepen.io/89905/coverflow--Blackrose-Cover-550x550.jpg" width="1200" height="1200" />
    </li>
    <li id="card_14">
        <img src="https://assets.codepen.io/89905/coverflow--FW-Imagine-Gold-Remixes2-550x550.jpg" width="1200" height="1200" />
    </li>
    <li id="card_15">
        <img src="https://assets.codepen.io/89905/coverflow--We-Are-COVER-MAIN-550x550.jpg" width="1200" height="1200" />
    </li>
    <li id="card_16">
        <img src="https://assets.codepen.io/89905/coverflow--Bath-House-Flat-550x550.jpg" width="1200" height="1200" />
    </li>
    <li id="card_17">
        <img src="https://assets.codepen.io/89905/coverflow--Pronoia-JPG-550x550.jpg" width="1200" height="1200" />
    </li>
    <li id="card_18">
        <img src="https://assets.codepen.io/89905/coverflow--Lapa9Theory-Cracking-Stores-no-Loci-logo-550x550.jpg" width="1200" height="1200" />
    </li>
    <li id="card_19">
        <img src="https://assets.codepen.io/89905/coverflow--EMANCIPATOR_MOM_AlbumCover-2000px-550x550.jpg" width="1200" height="1200" />
    </li>
    <li id="card_20">
        <img src="https://assets.codepen.io/89905/coverflow--MURGE-ep-cvr-3000x3000-550x550.jpg" width="1200" height="1200" />
    </li>
    <li id="card_21">
        <img src="https://assets.codepen.io/89905/coverflow--Emancipator_Laybrinth-ART-01-4000x4000-at-300dpi-550x550.jpg" width="1200" height="1200" />
    </li>
    <li id="card_22">
        <img src="https://assets.codepen.io/89905/coverflow--cover-550x550.jpg" width="1200" height="1200" />
    </li>
</ul>

<div class="warning">⚠️ Your browser does not support CSS Scroll-Linked Animations, so this demo won't work. If you're feeling adventurous use Chrome 89 with “Experimental Web Platform Features” enabled. Alternatively you can check out <a href="https://codepen.io/bramus/pen/PobZbBV" target="_top">a JS-based ScrollTimeline version <em>(with polyfills)</em></a> or <a href="https://twitter.com/bramus/status/1357391991114502144" target="_top" rel="noopener noreferrer">a recording of this demo</a></div>
              
            
!

CSS

              
                /*
  🐛 Bug #1

     I expected that the initial rendering should show card_0 at
     50% animation progress, as it's positioned halfway the scrollport.
     It — and its siblings — start at 0% though, no matter their position.

     When scrolling horizontally you see the first few items "catch up"
     with their animation state. By hitting item 8 the animation renders
     as expected: the item shown in the middle is animated at 50%.

     You can see the same "wrong" behavior when getting to the end: the
     last few items tend to run their animation short. By the time card_30
     is in the center it's animation progress is 100%, whereas I expected
     it to be at 50%.

 ✅ Bug #2

     When enabling scroll-snapping on .cards, the whole animation
     freaks out …

     👉 Fixed by animating the elements inside the li's, not the li's
        themselves.

  🐛 Bug #3

     The z-indexes aren't animated perfectly … from the right you'll see
     that the cover will appear over the preceding one for a little while.

     Above that it can — or cannot — be OK after a refresh.
*/

* {
  box-sizing: border-box;
  padding: 0;
  margin: 0;
}

:root {
  --cover-size: 15rem;
}
@media (max-width: 800px) {
	:root {
  		--cover-size: 9rem;
	}
}

body {
  background: #111;
  min-height: 100vh;
  font-family: sans-serif;

  display: flex;
  place-items: center;
}

.cards {
  list-style: none;
  overflow: scroll;
  width: 100%;
  white-space: nowrap;

  scroll-snap-type: x mandatory;
  outline: 1px solid #333;
  background: rgba(0 0 0 / 0.5);
}

.cards li {
  display: inline-block;
  width: var(--cover-size);
  height: var(--cover-size);
  scroll-snap-align: center;
}

.cards li img {
  dislay: block;
  width: var(--cover-size);
  height: var(--cover-size);
	
  -webkit-box-reflect: below 0.5em linear-gradient(rgba(0,0,0,0), rgba(0,0,0,0.25));
}

.cards {
  max-width: calc(var(--cover-size) * 6);
  margin: 0 auto;
  padding: calc(var(--cover-size) / 3 * 2) calc(50% - (var(--cover-size) / 3 * 2));
}

/* Show warning for older browser */
.warning {
  position: fixed;
  bottom: 1em;
  right: 1em;
  left: 1em;
  padding: 1em;
  border: 1px solid black;
  z-index: 9999;
  text-align: center;
  color: black;
  background: rgba(255 255 225 / 0.9);
}

.warning a {
  color: blue;
}

@supports (animation-timeline: works) {
  
  /* Hide Warning */
  .warning {
    display: none;
  }
  
  .cards {
    perspective: 40em;
  }
  
  /* Our animations */
  @keyframes adjust-z-index {
    0% {
      z-index: 1;
    }
    35% {
      z-index: 100;
    }
    50% {
      z-index: 10000;
    }
    65% {
      z-index: 100;
    }
    100% {
      z-index: 1;
    }
  }

  @keyframes rotate-cover {
    0% {
      transform: translateX(-100%) rotateY(-45deg);
    }
    35% {
      transform: translateX(0) rotateY(-45deg);
    }
    50% {
      transform: rotateY(0deg) translateZ(1em) scale(1.5);
    }
    65% {
      transform: translateX(0) rotateY(45deg);
    }
    100% {
      transform: translateX(100%) rotateY(45deg);
    }
  }
  
  /* 👀 Looking for the @scroll-timeline? You won't find those here but in
        the JS pane. Using JavaScript we generate the timeliens and attach
        them. We do this because we need to generate a Scroll Timeline for 
        each li, as selector() requires an id. This is quite cumbersome so
        we resort to JS for now.
  
        Relevant Bug: https://github.com/w3c/csswg-drafts/issues/5884
        
        No worries: the JS only generates CSS, so this demo is still pure
        CSS.
  */

  /* 🪝 Attach animations. Note that we attach a faux animation-timeline
        to prevent our animations from starting on load.
  
        We also apply the first part of our animation to the elements.
        This way we prevent a FOUC.
  */
  .cards li {
    animation: 1s linear adjust-z-index both;
    animation-timeline: faux-animation-timeline;
    /* Prevent FOUC */
    position: relative;
    z-index: 1;

	will-change: z-index;
  }

  .cards li > img {
    animation: 1s linear rotate-cover both;
    animation-timeline: faux-animation-timeline;
    /* Prevent FOUC */
    transform: translateX(-150%) rotateY(-45deg);

	will-change: transform;
  }
}

#debug {
  position: absolute;
  top: 1em;
  left: 1em;
}
#debug::after {
  content: " Show Debug";
  margin-left: 1.5em;
  color: white;
  white-space: nowrap;
}

#debug:checked + .cards {
  border: 1px solid lime;
}

#debug:checked + .cards li {
  text-align: center;
  color: white;
  border: 1px solid blue;
}

#debug:checked + .cards li::before {
  content: attr(id);
  display: block;
  position: absolute;
  inset: 0;
  line-height: var(--cover-size);
  opacity: 0.5;
}

#debug:checked + .cards li img {
  opacity: 0.5;
}
              
            
!

JS

              
                // @note: This is a little helper to quickly generate a Scroll Timeline for each li, as selector() requires an id until https://github.com/w3c/csswg-drafts/issues/5884 is resolved
// It only generates CSS, so this demo is still pure CSS ;)
const generateCSS = () => {
  let css = '';
  document.querySelectorAll('li').forEach((li, i) => {
    const id = li.getAttribute('id');

    css = `
      ${css}

      @scroll-timeline scroll-in-cards-${id} {
        source: selector(#cards);
        orientation: inline;
        start: selector(#${id}) end 0;
        end: selector(#${id}) start 0;
        scroll-offsets:
			selector(#${id}) end 0
			selector(#${id}) start 0
		;
        time-range: 1s;
      }

      /* Adjust the li on scroll (z-index) */
      #${id} {
        animation-timeline: scroll-in-cards-${id};
      }   

      /* Adjust the album cover on scroll (perspective) */
      #${id} > img {
        animation-timeline: scroll-in-cards-${id};
      }   
    `;
  });
  return css;
}

const injectCSS = (css) => {
  const style = document.createElement('style');
  style.innerHTML = css;
  document.head.appendChild(style);
}

injectCSS(generateCSS());
              
            
!
999px

Console