I have this carousel that needs a simple operation: appear infinite. The problem is that the animation cuts off and leaves a blank space at the end of the last element. I leave the code below and hope someone can help me.
.slider {
padding-top: 28px;
display: flex;
justify-content: center;
align-items: center;
width: 100%;
overflow: hidden;
}
.slider-items {
display: flex;
justify-content: center;
align-items: center;
gap: 40px;
animation: scroll 30s linear infinite;
}
@keyframes scroll {
0% {
transform: translateX(0%);
}
100% {
transform: translateX(-50%);
}
}
.slider-items img {
width: 12%;
margin: 40px;
filter: grayscale(100%);
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/react/18.2.0/umd/react.production.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/react-dom/18.2.0/umd/react-dom.production.min.js"></script>
<div className="slider pb-12">
<div className="slider-items">
<img src="https://picsum.photos/id/237/200/300" alt="" />
<img src="https://picsum.photos/seed/picsum/200/300" alt="" />
<img src="https://picsum.photos/200/300?grayscale" alt="" />
<img src="https://picsum.photos/200/300/?blur" alt="" />
<img src="https://picsum.photos/200/300.jpg" alt="" />
<img src="https://picsum.photos/id/237/200/300" alt="" />
<img src="https://picsum.photos/seed/picsum/200/300" alt="" />
<img src="https://picsum.photos/200/300?grayscale" alt="" />
<img src="https://picsum.photos/seed/picsum/200/300" alt="" />
<img src="https://picsum.photos/200/300?grayscale" alt="" />
<img src="https://picsum.photos/200/300.jpg" alt="" />
<img src="https://picsum.photos/id/237/200/300" alt="" />
</div>
</div>
I tried cloning the content, using sass, changing the seconds the animation lasts, the width of all the containers, changing the HTML structure and nothing works for me.
I added images and a container (which you were missing I think).
Pay attention to the 100% keyframe where half of the flex gap (or maybe half of the parent padding ? well you should test it :D) must be taken into account if you want the the animation to look smooth :)