Scroll · 18 of 34

Slide + Fade

A combined slide and fade, tuned so both finish together. This is the workhorse reveal for lists, cards and section intros.

HTML · CSS · JavaScript · No dependencies · MIT

HTML

<section class="slide-fade-section">
  <h2>Slide + Fade</h2>
</section>

CSS

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

.slide-fade-section h2 {
  font-size: 2.5rem;
  color: #f0f0f5;
  opacity: 0;
  transform: translateX(-50px);
  transition: opacity 0.7s cubic-bezier(0.16, 1, 0.3, 1),
              transform 0.7s cubic-bezier(0.16, 1, 0.3, 1);
}

.slide-fade-section.in-view h2 {
  opacity: 1;
  transform: translateX(0);
}

JavaScript

var section = document.querySelector('.slide-fade-section');

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