Scroll · 25 of 34

Image Reveal

An image is uncovered by a coloured curtain sliding away, a common editorial reveal. A pseudo-panel that transitions translateX over the picture.

HTML · CSS · JavaScript · No dependencies · MIT

HTML

<section class="img-reveal-section">
  <div class="img-reveal-wrapper">
    <div class="img-reveal-curtain"></div>
    <img src="https://picsum.photos/id/237/600/400" alt="Reveal">
  </div>
</section>

CSS

.img-reveal-section {
  min-height: 35vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.img-reveal-wrapper {
  position: relative;
  width: 300px;
  height: 200px;
  overflow: hidden;
}

.img-reveal-wrapper img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* A solid panel that slides away to reveal the image beneath */
.img-reveal-curtain {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: #7c5cff;
  transform: translateX(0);
  transition: transform 0.8s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 1;
}

.img-reveal-section.in-view .img-reveal-curtain {
  transform: translateX(100%);
}

JavaScript

var section = document.querySelector('.img-reveal-section');

new IntersectionObserver(function (entries) {
  entries.forEach(function (entry) {
    entry.target.classList.toggle('in-view', entry.isIntersecting);
  });
}, { threshold: 0.25 }).observe(section);