Better Netflix Carousel using SwiperJS

By Raddy in CSS JavaScript ·

This is a remake of my first YouTube tutorial that I did showing you how to create a simple Netflix looking like slider. This time I wanted to take it a step further by using a JavaScript framework called SwiperJS. SwiperJS has amazing API options that we can use to build amazing easy to use carousels.

First of all, make sure you download SwiperJS from here: https://swiperjs.com/

HTML

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <title>Netflix 1.1</title>
  <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1">

  <!-- Link Swiper's CSS -->
  <link rel="stylesheet" href="../package/css/swiper.min.css">
  <link rel="stylesheet" href="css/styles.css">

  <!-- Demo styles -->
  <style>

  </style>
</head>
<body>
  <!-- Swiper -->
  <h1>NETFLIX</h1>

  <div class="netflix-slider">
    <h2>Popular on Netflix</h2>
    <div class="swiper-container">
      <div class="swiper-wrapper">
        <div class="swiper-slide"><img src="img/1.jpg" alt="Movie Title"></div>
        <div class="swiper-slide"><img src="img/2.jpg" alt="Movie Title"></div>
        <div class="swiper-slide"><img src="img/3.jpg" alt="Movie Title"></div>
        <div class="swiper-slide"><img src="img/4.jpg" alt="Movie Title"></div>
        <div class="swiper-slide"><img src="img/5.jpg" alt="Movie Title"></div>
        <div class="swiper-slide"><img src="img/6.jpg" alt="Movie Title"></div>
        <div class="swiper-slide"><img src="img/7.jpg" alt="Movie Title"></div>
        <div class="swiper-slide"><img src="img/8.jpg" alt="Movie Title"></div>
        <div class="swiper-slide"><img src="img/9.jpg" alt="Movie Title"></div>
        <div class="swiper-slide"><img src="img/10.jpg" alt="Movie Title"></div>
      </div>
      <!-- Add Pagination -->
      <!-- <div class="swiper-pagination"></div> -->
      <div class="swiper-button-next"></div>
      <div class="swiper-button-prev"></div>
    </div>
  </div>

  <div class="netflix-slider">
    <h2>Continue watching...</h2>
    <div class="swiper-container">
      <div class="swiper-wrapper">
        <div class="swiper-slide"><img src="img/1.jpg" alt="Movie Title"></div>
        <div class="swiper-slide"><img src="img/2.jpg" alt="Movie Title"></div>
        <div class="swiper-slide"><img src="img/3.jpg" alt="Movie Title"></div>
        <div class="swiper-slide"><img src="img/4.jpg" alt="Movie Title"></div>
        <div class="swiper-slide"><img src="img/5.jpg" alt="Movie Title"></div>
        <div class="swiper-slide"><img src="img/6.jpg" alt="Movie Title"></div>
        <div class="swiper-slide"><img src="img/7.jpg" alt="Movie Title"></div>
        <div class="swiper-slide"><img src="img/8.jpg" alt="Movie Title"></div>
        <div class="swiper-slide"><img src="img/9.jpg" alt="Movie Title"></div>
        <div class="swiper-slide"><img src="img/10.jpg" alt="Movie Title"></div>
      </div>
      <!-- Add Pagination -->
      <!-- <div class="swiper-pagination"></div> -->
      <div class="swiper-button-next"></div>
      <div class="swiper-button-prev"></div>
    </div>
  </div>

  <!-- Swiper JS -->
  <script src="../package/js/swiper.min.js"></script>

  <!-- Initialize Swiper -->
  <script>
    var swiper = new Swiper('.swiper-container', {
      slidesPerView: 6,
      spaceBetween: 10,
      slidesPerGroup: 2,
      pagination: {
        el: '.swiper-pagination',
        clickable: true,
      },
      navigation: {
        nextEl: '.swiper-button-next',
        prevEl: '.swiper-button-prev',
      },
    });
  </script>
</body>
</html>

SCSS

html, body {
    position: relative;
    height: 100%;
  }
  body {
    background: #000;
    font-family: Helvetica Neue, Helvetica, Arial, sans-serif;
    font-size: 14px;
    color:#fff;
    margin: 0;
    padding: 0;
  }
  .swiper-container {
    width: 100%;
    height: 100%;
  }
  .swiper-slide {
    text-align: center;
    font-size: 18px;
    /* Update: Removed the Flex property - IE FIX */
  }

  img {
      max-width: 100%;
      height: auto;
  }


  h1 {
      font-family: Arial, Helvetica, sans-serif;
      color: red;
      text-align: center;
  }

    :root {
        --swiper-theme-color: #fff;
    }

  .netflix-slider {
    .swiper-wrapper {
        padding: 20px 0;
    }

    .swiper-slide {
        transition: 250ms all;

        &:hover {
            transform: scale(1.2);
            z-index: 1;
        }

        &:first-child:hover{
            margin:0 40px;
        }

        &:last-child:hover{
            margin:0 -40px;
        }

    }


  }

Compiled CSS (if you need it)

html, body {
  position: relative;
  height: 100%;
}

body {
  background: #000;
  font-family: Helvetica Neue, Helvetica, Arial, sans-serif;
  font-size: 14px;
  color: #fff;
  margin: 0;
  padding: 0;
}

.swiper-container {
  width: 100%;
  height: 100%;
}

.swiper-slide {
  text-align: center;
  font-size: 18px;
  
  /* Update: Removed the Flex property - IE FIX */
 
}

img {
  max-width: 100%;
  height: auto;
}

h1 {
  font-family: Arial, Helvetica, sans-serif;
  color: red;
  text-align: center;
}

:root {
  --swiper-theme-color: #fff;
}

.netflix-slider .swiper-wrapper {
  padding: 20px 0;
}

.netflix-slider .swiper-slide {
  -webkit-transition: 250ms all;
  transition: 250ms all;
}

.netflix-slider .swiper-slide:hover {
  -webkit-transform: scale(1.2);
          transform: scale(1.2);
  z-index: 1;
}

.netflix-slider .swiper-slide:first-child:hover {
  margin: 0 40px;
}

.netflix-slider .swiper-slide:last-child:hover {
  margin: 0 -40px;
}
/*# sourceMappingURL=styles.css.map */

Full download if you don’t feel like copying and pasting the code above. Don’t donate, just put 0.

  1. John says:

    I’m seeing the videos display vertically in both Chrome & Firefox. Is there an error with the source code?

    1. Raddy says:

      Is that when you go fullscreen on mobile?

  2. Sebastian says:

    same problem: on ie11 it is vertically, in firefox it works.

    1. Raddy says:

      IE doesn’t support the flex property. The fix would be to remove everything display flex from .swiper-slide class name

Leave a Reply

Your email address will not be published. Required fields are marked *