3

I am using flickity slider and it's working. What I am doing is, I have to start my slider from my heading like below image

enter image description here

and when it's slide then it will go to the left side till viewport.

enter image description here

I tried below code.

$('.main-carousel').flickity({
  freeScroll: true,
  cellAlign: 'left',
  wrapAround: true,
  contain: true,
  prevNextButtons: false,
  pageDots: true,
  draggable: false
});
.headingwrap {
  margin-left: 10%;
}

.carousel-cell {
  width: 30%;
  height: 250px;
}

.one {
  background-color: red
}

.two {
  background-color: green
}

.three {
  background-color: orange
}

.four {
  background-color: blue
}

.five {
  background-color: black
}
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/flickity/2.2.1/flickity.min.css">
<section>
  <div class="headingwrap">
    <h2>This is the heading </h2>
  </div>
  <div class="main-carousel">
    <div class="carousel-cell one"></div>
    <div class="carousel-cell two"></div>
    <div class="carousel-cell three"></div>
    <div class="carousel-cell four"></div>
    <div class="carousel-cell five"></div>
  </div>

</section>



<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/flickity/2.2.1/flickity.pkgd.min.js"></script>

This is second snippet and just added

.flickity-viewport{margin-left: 10%;}

$('.main-carousel').flickity({
  freeScroll: true,
  cellAlign: 'left',
  wrapAround: true,
  contain: true,
  prevNextButtons: false,
  pageDots: true,
  draggable: false
});
.flickity-viewport {
  margin-left: 10%;
}

.headingwrap {
  margin-left: 10%;
}

.carousel-cell {
  width: 25%;
  height: 250px;
}

.one {
  background-color: red
}

.two {
  background-color: green
}

.three {
  background-color: orange
}

.four {
  background-color: blue
}

.five {
  background-color: black
}
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/flickity/2.2.1/flickity.min.css">
<section>
  <div class="headingwrap">
    <h2>This is the heading </h2>
  </div>
  <div class="main-carousel">
    <div class="carousel-cell one"></div>
    <div class="carousel-cell two"></div>
    <div class="carousel-cell three"></div>
    <div class="carousel-cell four"></div>
    <div class="carousel-cell five"></div>
  </div>

</section>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/flickity/2.2.1/flickity.pkgd.min.js"></script>
Temani Afif
  • 245,468
  • 26
  • 309
  • 415
user9437856
  • 2,360
  • 2
  • 33
  • 92

0 Answers0