<div class="snap-container">
  <div class="video-trailer">
    <video id="trailer1" src="https://res.cloudinary.com/dsderm9xw/video/upload/v1733975799/Squid_Game__Season_2_za2com.mp4" muted controls loop></video>
    <div class="trailer-info">
      <h2>Squid Game: Season 2</h2>
      <p>Official Trailer</p>
      <p>Only on Netflix, December 26, 2024</p>
      <div class="genre-tag"> Thriller </div>
    </div>
  </div>
  <div class="video-trailer">
    <video id="trailer2" src="https://res.cloudinary.com/dsderm9xw/video/upload/v1733975239/videoplayback_cy2rg5.mp4" muted controls loop></video>
    <div class="trailer-info">
      <h2>How To Train Your Dragon</h2>
      <p>Official Trailer</p>
      <p>In Theaters June 13</p>
      <div class="genre-tag"> Animation </div>
    </div>
  </div>
  <div class="video-trailer">
    <video id="trailer3" src="https://res.cloudinary.com/dsderm9xw/video/upload/v1733976488/videoplayback_1_s2eb3p.mp4" muted controls loop></video>
    <div class="trailer-info">
      <h2> Wicked </h2>
      <p>Official Trailer</p>
      <p>In Theaters Nov 27</p>
      <div class="genre-tag">Fantasy Fiction</div>
    </div>
  </div>
</div>
body,
html {
  margin: 0;
  padding: 0;
  font-family: "Arial", sans-serif;
  background-color: #000;
  color: white;
}

.snap-container {
  height: 100vh;
  overflow-y: scroll;
  scroll-snap-type: y mandatory;
}

.video-trailer {
  height: 100vh;
  width: 100%;
  scroll-snap-align: start;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  position: relative;
  overflow: hidden;
}

.video-trailer video {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.trailer-info {
  position: relative;
  z-index: 2;
  text-align: center;
  padding: 20px;
  max-width: 80%;
}

.trailer-info h2 {
  font-size: 3rem;
  margin-bottom: 10px;
  text-shadow: 2px 2px 4px rgba(0, 0, 0, 0.5);
}

.trailer-info p {
  font-size: 1.2rem;
  opacity: 0.8;
}

.genre-tag {
  display: inline-block;
  background-color: rgba(255, 255, 255, 0.2);
  padding: 5px 15px;
  border-radius: 20px;
  margin-top: 15px;
  font-size: 0.9rem;
}
const snapContainer = document.querySelector(".snap-container");
const trailers = document.querySelectorAll("video");

snapContainer.addEventListener("scrollsnapchange", (event) => {
  const visibleTrailer = event.snapTargetBlock.children[0];

  if (visibleTrailer) {
    visibleTrailer.play();
  }
});

snapContainer.addEventListener("scrollsnapchanging", (event) => {
  const visibleTrailer = event.snapTargetBlock.children[0];
  if (visibleTrailer) {
    visibleTrailer.pause();
  }
});

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

This Pen doesn't use any external JavaScript resources.