I have this code for images that are display for infinite slide and this works fine but as soon as I add overflow-x: scroll to logos div it is not infinite anymore and I can’t scroll both ways.
–>What I want to achieve is the pictures slide automatically but at the same time I can scroll back and forth by myself and that doesn’t affect the automatic sliding.
HTML
<div class="logos-slide">
<img src="./logos/Boss.png" />
<img src="./logos/1.png" />
<img src="./logos/2.png" />
<img src="./logos/3.png" />
<img src="./logos/4.png" />
<img src="./logos/5.png" />
<img src="./logos/6.png" />
<img src="./logos/7.png" />
<img src="./logos/8.png" />
</div>
</div>
<script>
var copy = document.querySelector(".logos-slide").cloneNode(true);
document.querySelector(".logos").appendChild(copy);
</script>
CSS
.logos::-webkit-scrollbar {
display: none;
}
@keyframes slide {
from {
transform: translateX(0);
}
to {
transform: translateX(-100%);
}
}
.logos {
overflow: scroll;
overflow-x: scroll;
padding: 60px 0;
white-space: nowrap;
position: relative;
}
.logos:before,
.logos:after {
position: absolute;
top: 0;
width: 250px;
height: 100%;
content: "";
z-index: 2;
}
.logos:click .logos-slide {
animation-play-state: paused;
}
.logos-slide {
display: inline-block;
animation: 5s slide infinite linear;
}
.logos-slide img {
height: 100px;
margin: 0 2.5px;
filter: drop-shadow(0px 0px 10px rgba(0, 0, 0, 0.75));
}
2
Answers
I found out the solution to my question and here it is if someone needs it Basically what happens you have 3 rows of images row 1, 3 and 5 slide from left to right and the rest is the opposite and you can manually slide through them.
HTML
CSS
You can change display to flex and add hover state to the animated element:
Note: If you want to be able scroll all elements, set
animation: none
in hover state. However, this will reset element positions.