Moving Carousel Delay/Jump

Viewed 67

Basically I have a moving carousel which I created using key-frames, however;

Problem: After the key-frame animation has ended there seems to be a delay before the next animation has starts again. After some research, I came upon this: requestAnimationFrame, however I'm not too sure(or comfortable enough) on implementing it. Any help would be appreciated, thanks.

enter image description here

Here is what I have so far:

const slider = document.querySelectorAll('.image-container');
slider.forEach((dropdown) => {
  dropdown.classList.toggle("animate");
});
.carousel-wrapper {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.carousel-slider {
  height: 100px;
  position: relative;
  display: flex;
  overflow: hidden;
}

.animate {
  height: 100px;
  display: flex;
  align-items: center;
  animation: slideshow 5s linear infinite;
}

.image-container img {
  height: 85px;
  padding: 0 8px 0 8px;
}

@keyframes slideshow {
  0% {
    transform: translateX(0);
  }
  100% {
    transform: translateX(-100%);
  }
}

.carousel-slider::before,
.slider::after {
  height: 100px;
  width: 50px;
  position: absolute;
  content: "";
  background: linear-gradient(to right, rgba(255, 255, 255, 0) 100%);
  z-index: 2;
}

.carousel-slider::before {
  left: 0;
  top: 0;
}

.carousel-slider::after {
  right: 0;
  top: 0;
  transform: rotateZ(180deg);
}
<div style="max-width: 800px;">
  <div class="carousel-wrapper">
    <div class="carousel-slider">
      <div class="image-container">
        <a href="#"><img src="https://images.unsplash.com/photo-1444464666168-49d633b86797?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1169&q=80" alt="image1"></a>
        <a href="#"><img src="https://images.unsplash.com/photo-1529257414772-1960b7bea4eb?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1170&q=80" alt="image2"></a>
        <a href="#"><img src="https://images.unsplash.com/photo-1584028887908-f6d2257fe9d4?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1170&q=80" alt="image3"></a>
      </div>
      <div class="image-container">
        <a href="#"><img src="https://images.unsplash.com/photo-1444464666168-49d633b86797?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1169&q=80" alt="image1"></a>
        <a href="#"><img src="https://images.unsplash.com/photo-1529257414772-1960b7bea4eb?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1170&q=80" alt="image2"></a>
        <a href="#"><img src="https://images.unsplash.com/photo-1584028887908-f6d2257fe9d4?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1170&q=80" alt="image3"></a>
      </div>
    </div>
  </div>
</div>

0 Answers
Related