How To Add A Responsive Video Gallery To Your Blogger Website

CSS:



.video-gallery-container {
  width: 900px;
  font-family: "Roboto", sans-serif;
  background: #ffd166;
  padding: 8px 0 0 0;
  margin: 0 auto;
}

.video-gallery-container,
.video-gallery-container * {
  box-sizing: border-box;
}

.video-gallery-container h2.title {
  text-align: center;
  font-weight: 300;
  text-transform: uppercase;
  font-size: 34px;
  margin-bottom: 24px;
}

.video-gallery-container .video-gallery {
  display: flex;
  background: #02151e;
  justify-content: center;
  padding: 16px;
  padding-top: 24px;
  gap: 24px;
  color: #fff;
}

.video-gallery h3.video-title {
  line-height: 1.6;
  font-weight: 700;
  font-size: 20px;
  width: 100%;
}

.video-gallery .thumbnail {
  height: 120px;
  cursor: pointer;
}

.video-gallery .video {
  position: relative;
}

.video-gallery .video:hover .play-icon {
  opacity: 1;
}

.video-gallery .play-icon {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  pointer-events: none;
  opacity: 0;
  transition: opacity 400ms ease;
}

.video-gallery .video .play-icon img {
  height: 50px;
  width: 50px;
}

.video-gallery .all-videos {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.video-gallery .responsive-iframe {
  position: relative;
  height: 0;
  overflow: hidden;
  padding-top: 56.25%;
  padding-bottom: 30px;
}

.video-gallery .responsive-iframe iframe {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
}

@media (max-width: 900px) {
  .video-gallery-container {
    width: 100%;
  }
}

@media (max-width: 700px) {
  .video-gallery-container .video-gallery {
    flex-direction: column;
  }

  .video-gallery .all-videos {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .video-gallery .thumbnail {
    height: unset;
    width: 100%;
  }
}

@media (max-width: 500px) {
  .video-gallery .all-videos {
    grid-template-columns: 1fr;
  }

  .video-gallery-container {
    max-width: 400px;
  }

  .video-gallery-container h2.title {
    font-size: 24px;
    font-weight: bold;
  }
}




JAVA SCRIPT



const videoThumbnails = document.querySelectorAll(
  ".video-gallery .all-videos .thumbnail"
);
const videoPlayer = document.querySelector(
  ".video-gallery .featured-video iframe"
);
const videoTitle = document.querySelector(".video-gallery .video-title");

const showVideo = (videoId, title) => {
  let videoUrl = `https://www.youtube.com/embed/${videoId}?rel=0`;
  videoPlayer.setAttribute("src", videoUrl);
  videoTitle.innerHTML = title;
};

videoThumbnails.forEach((v) => {
  v.addEventListener("click", () => {
    showVideo(v.dataset.id, v.dataset.title);
  });
});






<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <link rel="stylesheet" href="style.css" />
  </head>
  <body>
    <div class="video-gallery-container">
      <h2 class="title">Best videos on Designing</h2>

      <div class="video-gallery">
        <div class="featured-video">
          <div class="responsive-iframe">
            <iframe
              width="560"
              height="315"
              src="https://www.youtube.com/embed/stqXwwEkF0g?rel=0"
              title="YouTube video player"
              frameborder="0"
              allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture"
              allowfullscreen
            ></iframe>
          </div>

          <h3 class="video-title">
            Design Responsive Course Cards Using HTML, CSS & JavaScript
          </h3>
        </div>

        <div class="all-videos">
          <div class="video">
            <img
              class="thumbnail"
              data-id="stqXwwEkF0g"
              data-title="Design Responsive Course Cards Using HTML, CSS & JavaScript"
              src="images/thumbnail-1.jpeg"
              alt=""
            />

            <div class="play-icon">
              <img src="images/play-icon.png" alt="" />
            </div>
          </div>

          <div class="video">
            <img
              class="thumbnail"
              data-id="ohFuDyhED8s"
              data-title="Design A Responsive Portfolio Website Using HTML, CSS & JS"
              src="images/thumbnail-2.jpeg"
              alt=""
            />

            <div class="play-icon">
              <img src="images/play-icon.png" alt="" />
            </div>
          </div>

          <div class="video">
            <img
              class="thumbnail"
              data-id="prX_NC3Nbh8"
              data-title="Design A Responsive Homepage Using HTML, CSS For Blogger"
              src="images/thumbnail-3.jpeg"
              alt=""
            />

            <div class="play-icon">
              <img src="images/play-icon.png" alt="" />
            </div>
          </div>
        </div>
      </div>
    </div>

    <script src="main.js"></script>
  </body>
</html>




Post a Comment

أحدث أقدم