Swipeable Card Design using Swiper JS

Here is an example for Swipeable Card Design using swiper js.

For swipeable Card design needs div with classes swiper,swiper-wrapper and swiper-slide respectively.Content that is to displayed inside the card must be included in the div with class “swiper-slide”.In this example,5 cards are displayed .Therefore five div with class “swiper-slide” is used.Height and weight of div with class “swiper” is need to be set.Any other css needed to be add can be included by adding project/task specific classes.

Important thing to be added is  effect: “cards” during initialization of swiper.

<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="utf-8" />
  <title>Swiper demo</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="https://cdn.jsdelivr.net/npm/swiper@9/swiper-bundle.min.css" />

 <!-- Demo styles -->
  <style>
    html,
    body {
      position: relative;
      height: 100%;
    }

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

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

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

    body {
      display: flex;
      justify-content: center;
      align-items: center;
    }

    .swiper {
      width: 240px;
      height: 320px;
    }

    .swiper-slide {
      display: flex;
      align-items: center;
      justify-content: center;
      border-radius: 18px;
      font-size: 22px;
      font-weight: bold;
      color: #fff;
    }

    .swiper-slide:nth-child(1n) {
      background-color: rgb(206, 17, 17);
    }

    .swiper-slide:nth-child(2n) {
      background-color: rgb(0, 140, 255);
    }

    .swiper-slide:nth-child(3n) {
      background-color: rgb(10, 184, 111);
    }

    .swiper-slide:nth-child(4n) {
      background-color: rgb(211, 122, 7);
    }

    .swiper-slide:nth-child(5n) {
      background-color: rgb(118, 163, 12);
    }

   
  </style>
</head>

<body>
  <!-- Swiper -->

  <div class="swiper mySwiper">
    <div class="swiper-wrapper">
      <div class="swiper-slide">Card 1</div>
      <div class="swiper-slide">Card 2</div>
      <div class="swiper-slide">Card 3</div>
      <div class="swiper-slide">Card 4</div>
      <div class="swiper-slide">Card 5</div>
    
    </div>
  </div>

  <!-- Swiper JS -->
  <script src="https://cdn.jsdelivr.net/npm/swiper@9/swiper-bundle.min.js"></script>

  <!-- Initialize Swiper -->
  <script>
    var swiper = new Swiper(".mySwiper", {
      effect: "cards",
      grabCursor: true,
    });
  </script>
</body>

</html>

Leave a comment

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