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

Auto Save

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

              
                <main class="">
  <div></div>
  <div></div>
  <div></div>
  <div></div>
  <div></div>
  <div class="primary"></div>
</main>

<form>
  <button type="button" class="active" data-step="0">1</button>
  <button type="button" data-step="1">2</button>
  <button type="button" data-step="2">3</button>
</form>
<p class="step1">Add six frames. For each frame overlay a repeating gradient of 1px transparent and 5px white. Offset this gradient by 1px for each frame.</p>
<p class="step2">Apply a mix-blend-mode of multiply to each frame, letting the underlying frames to show instead of the white blocks from the gradient.</p>
<p class="step3">Add a cover on top that is 1px transparent and 5px black. Translate it 5px infinitely. The underlying frames will show through one at a time.</p>
              
            
!

CSS

              
                :root {
  --pixel: 1px;
  --cover: #212123;
  --duration: 1000ms;
  --covered: calc(var(--pixel) * 5); /*6 frames, 5 covered at a time */
  --space: white; /* will cause transparency when mix blend mode multiply */
  --w: 100vw;
  --h: 100vh;
  
  --depth-base: 0px;
  --direction: alternate;
  
  --blend: none;
}
main *, main *::after {
  opacity: 0;
}
main div {
  --offset: calc(var(--pixel) * 1);
  --background-image: radial-gradient(circle, cyan 0%, cyan);
  --background-cover-yes: linear-gradient(to right, transparent 0, transparent calc(var(--pixel)), var(--space) var(--pixel), var(--space) calc(var(--covered)));
  --background-cover-no: linear-gradient(to right, transparent, transparent);
  --background-cover: var(--background-cover-no);
  
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  overflow: hidden;
  background-color: #16161c;
  background-image: var(--background-cover),
    var(--background-image);
  mix-blend-mode: var(--blend);
  
  background-position: calc(var(--offset) - calc(var(--pixel) * 1)) 0, center center;
  background-size: calc(var(--pixel) * 6) 100%, cover;
  background-repeat: repeat, no-repeat;
  transition: background 750ms ease-in-out;
  
  filter: saturate(200%);
}

main div:nth-of-type(2) {
  --offset: calc(var(--pixel) * 2);
  --background-image: radial-gradient(circle, hotpink 0%, cyan 20%);
}
main div:nth-of-type(3) {
  --offset: calc(var(--pixel) * 3);
  --background-image: radial-gradient(circle, hotpink 20%, cyan 40%);
}
main div:nth-of-type(4) {
  --offset: calc(var(--pixel) * 4);
  --background-image: radial-gradient(circle, hotpink 40%, cyan 60%);
}
main div:nth-of-type(5) {
  --offset: calc(var(--pixel) * 5);
  --background-image: radial-gradient(circle, hotpink 60%, cyan 75%);
}
main div:nth-of-type(6) {
  --offset: calc(var(--pixel) * 6);
  --background-image: radial-gradient(circle, hotpink 80%, cyan);
}

/*want to try using your own frames? insert them here, with either a gradient or an image with url() */
/**/
main div:nth-of-type(1) {
  --background-image: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/61811/h1.jpg);
}
main div:nth-of-type(2) {
  --background-image: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/61811/h2.jpg);
}
main div:nth-of-type(3) {
  --background-image: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/61811/h3.jpg);
}
main div:nth-of-type(4) {
  --background-image: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/61811/h4.jpg);
}
main div:nth-of-type(5) {
  --background-image: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/61811/h5.jpg);
}
main div:nth-of-type(6) {
  --background-image: url(https://s3-us-west-2.amazonaws.com/s.cdpn.io/61811/h6.jpg);
}
/**/



/*the sliding cover that triggers the motion illusion */
.primary::after {
  content: '';
  position: absolute;
  top: 0;
  right: calc(var(--pixel) * -12);
  bottom: 0;
  left: calc(var(--pixel) * -12);
  background: linear-gradient(to right, transparent 0px, transparent calc(var(--pixel) * 1), var(--cover) calc(var(--pixel) * 1), var(--cover) calc(var(--pixel) * 6));
  will-change: transform, opacity;
  transition: opacity var(--duration) linear;
  mix-blend-mode: normal;
  opacity: var(--show, 0);
  transform: translateX(var(--slide-amount, 0));
  background-size: calc(var(--pixel) * 6) 100%;
  
  animation: var(--animation, none) var(--duration) infinite var(--direction) linear;
}

@keyframes cover {
  100% {
    transform: translateX(calc(var(--pixel) * 5))
  }
}

main {
  width: var(--w);
  height: var(--h);
  position: relative;
  transition: transform var(--duration) ease-in-out;
  background: white;
  transform: scale(1);
}
*, *::after {
  box-sizing: border-box;
}










body {
  width: 100%;
  height: 100vh;
  display: flex;
  justify-content: center;
  align-items: center;
  background: hsl(203, 50%, 4%);
  margin: 0;
  overflow: hidden;
  touch-action: none;
  
  font-family: system-ui, -apple-system, 'Segoe UI', sans-serif
}
form {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  padding: .2rem 1rem;
  text-align: center;
  
  background: rgba(245,245,255,.86);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  --form-color-alpha: rgba(150, 250, 255, .1);
  overflow: auto;
}
form div {
  padding: .5rem .5rem;
  font-size: 12px;
  transform: translateX(1rem);
}
form label {
  transform: translateX(-1.5rem)
}
p {
  position: absolute;
  line-height: 1.334;
  bottom: 0;
  left:0;
  right:0;
  
  padding: .5rem 1rem;
  text-align: center;
  
  background: rgba(245,245,255,1);
  display: flex;
  align-items: center;
  justify-content: center;
  
  opacity: 0;
}
code {
  display: inline;
  font-family: monospace;
}


button {
  appearance: none;
  border: 0;
  border-radius: 50%;
  font-size: 1rem;
  margin: .5rem 1rem;
  width: 2rem;
  height: 2rem;
  background-color: hsl(193, 50%, 90%);
  transition: background-color 350ms ease-in-out;
}
button.active {
  background-color: hsl(193, 50%, 50%);
  color: #fafaff;
}
              
            
!

JS

              
                var frames = Array.from(document.querySelectorAll('main div'));
var explanations = Array.from(document.querySelectorAll('p[class*=step]'));
var steps = document.querySelectorAll('button');
var duration = 1000;

buildFrames();

function buildFrames(finish) {
  document.documentElement.style.setProperty('--show', 0);
  changeExplanation(0);
  var dur = finish === true ? 0 : duration;
  for (let i = 0, l = frames.length; i < l; ++i) {
    let frame = frames[i];
    var framer = frame.animate({opacity: [0,1]}, {
      duration: dur,
      fill: 'both',
      delay: dur * 2 * i
    });
    framer.onfinish = function() {
      var masker = frame.animate({backgroundImage: ['var(--background-cover-no),var(--background-image)','var(--background-cover-yes),var(--background-image)']}, {
        duration: dur,
        fill: 'both',
        delay: 0
      });

      if (i === l-1) {
        masker.onfinish = startBlendModes;
      }
    };
  }
}


function startBlendModes(finish) {
  document.documentElement.style.setProperty('--show', 0);
  changeExplanation(1);
  var dur = finish === true ? 0 : duration;
  for (let i = frames.length - 1, count = 0; i >= 0; --i) {
    let frame = frames[i];
    var framer = frame.animate({mixBlendMode: ['normal','multiply']}, {
      duration: dur * 1.5,
      fill: 'both',
      delay: dur * (count++) * 1.5
    });
    
    if (i === 0) {
      framer.onfinish = startCover;
    }
  }
}

function startCover() {
  document.documentElement.style.setProperty('--show', 1);
  changeExplanation(2);
  
  setTimeout(() => {
    document.documentElement.style.setProperty('--animation', 'cover');
  }, duration * 3)
}

function changeExplanation(index) {
  explanations[index].animate({opacity:[0,1]}, {
    duration: 250,
    fill: 'both'
  });
  document.querySelector('.active').classList.remove('active');
  steps[index].classList.add('active');
}

function clearAnimations() {
  if (document.getAnimations) {
    document.getAnimations().forEach(function(anim) {
      anim.cancel();
    });
  }
}

// for (let i = 0; i < steps.length; ++i) {
//   steps[i].addEventListener('click', changeStep);
// }
function changeStep(e) {
  var index = parseInt(e.currentTarget.getAttribute('data-step'), 10);
  clearAnimations() 
  
  if (index === 0) {
    buildFrames();
  } else if (index === 1) {
    buildFrames(true);
    startBlendModes();
  } else {
    buildFrames(true);
    startBlendModes(true);
    startCover();
  }
}
              
            
!
999px

Console