Cycle2 JS center active slide

Using Cycle 2 (https://jquery.malsup.com/cycle2/) I am trying to make the active slide centered – by default it is the left of 3 slides that is active (x3 visible) data-cycle-carousel-visible="3" so my caption doesnt match with the centred slide.

Any help much appreciated 🙂

body {
  font-family: Arial, sans-serif;
  font-style: normal;
  font-size: 18px;
  line-height: 22px;
  margin: 0;
  padding: 0;
  color: #000;
}

img {
  width: 100%;
  height: auto;
  display: block;
}

.module-content {
  padding-bottom: 40px;
}

.cycle-slideshow-nav {
  position: relative;
  height: 50px;
}

.slideshow-caption {
  text-align: center;
  height: 50px;
  line-height: 50px;
}

.module-bleed-img {
  position: relative;
  overflow: hidden;
}

.module-bleed-img .cycle-slideshow {
  position: absolute;
  width: 130%;
  top: 0;
  left: 50%;
  transform: translate(-50%, 0%);
}

.bleed-img {
  padding: 0 40px;
}
<div class="module-bleed-img module-content">
  <div class="cycle-slideshow" data-cycle-slides=".bleed-img" data-cycle-swipe="true" data-cycle-swipe-fx="scrollHorz" data-cycle-fx="carousel" data-cycle-timeout="0" data-cycle-carousel-visible="3" data-cycle-carousel-fluid="true" data-cycle-prev="#prev-4"
    data-cycle-next="#next-4" data-cycle-caption="#caption-4" data-cycle-caption-template="{{slideNum}}: {{cycleTitle}}">
    <div class="bleed-img" data-cycle-title="slide A"><img src="https://work.creativeramp.com/London/Internal/www/images/sample_3x4.jpg" alt="">
    </div>
    <div class="bleed-img" data-cycle-title="slide B"><img src="https://work.creativeramp.com/London/Internal/www/images/sample_3x4.jpg" alt="">
    </div>
    <div class="bleed-img" data-cycle-title="slide C"><img src="https://work.creativeramp.com/London/Internal/www/images/sample_3x4.jpg" alt="">
    </div>
  </div>
  <div class="cycle-slideshow-nav">
    <button id="prev-4" class="prev-btn">Prev</button>
    <button id="next-4" class="next-btn">Next</button>
    <div id="caption-4" class="slideshow-caption"></div>
  </div>
</div>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://malsup.github.io/jquery.cycle2.js"></script>
<script src="https://malsup.github.io/min/jquery.cycle2.carousel.min.js"></script>
<script src="https://malsup.github.io/min/jquery.cycle2.center.min.js"></script>

Leave a Comment