I'm looking to design something similar to a desktop-only carousel. Here's the code snippet I have:
<div class="wrapper">
<div class="image-container">
<img alt="Siac" src="https://diey.now.sh/Icons/Clients/SIAC_LOGO.svg">
<img alt="Change" src="https://diey.now.sh/Icons/Clients/CHANGE_LOGO.svg">
<img alt="HF" src="https://diey.now.sh/Icons/Clients/H_F_Logo.svg">
<img alt="VDM" src="https://diey.now.sh/Icons/Clients/VDM_Logo.svg">
<img alt="Reviu" src="https://diey.now.sh/Icons/Clients/Reviu_Logo.svg">
<img alt="Total Capital" src="https://diey.now.sh/Icons/Clients/Total_Capital_Logo.svg">
<img alt="AdelantaT" src="https://diey.now.sh/Icons/Clients/AdelantaT_Logo.svg">
<img alt="Ayssa" src="https://diey.now.sh/Icons/Clients/Ayssa_Logo.svg">
<img alt="Carga Logística" src="https://diey.now.sh/Icons/Clients/Carga_Logistica_Logo.svg">
</div>
</div>
/* Adding padding based on screen width */
.wrapper {
padding: 0 2.5em;
@media (min-width: 1024px) {
padding: 0 8em;
}
@media (min-width: 1280px) {
padding: 0 12em;
}
}
.image-container {
@media (min-width: 768px) {
display: flex;
overflow-x: scroll;
width: 100%;
::-webkit-scrollbar {
width: 0px;
background: transparent;
}
}
}
img {
@media (min-width: 768px) {
height: 100px;
width: 240px;
flex-shrink: 0;
animation: moveSlideShow 9s ease-in-out alternate infinite;
@keyframes moveSlideShow {
100% {
transform: translateX(-1440px);
}
}
}
@media (min-width: 1280px) {
@keyframes moveSlideShow {
100% {
transform: translateX(-1200px);
}
}
}
}
If you check the transform, it works well for specific screen sizes due to image widths. How can we calculate the correct translateX value dynamically?
This project is built using React.js and Styled-components. Any suggestions or solutions using tools like React-spring would be appreciated as I explore its capabilities :)