<div class="view" id="view">
<div class="inner">
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
<div class="item"></div>
</div>
</div>
html,
body {
margin: 0;
height: 100%;
display: grid;
place-content: center;
}
.view {
position: relative;
width: 400px;
height: 250px;
counter-reset: num 0;
animation: scroll 1s infinite;
overflow: hidden;
}
.view:hover {
animation-play-state: paused;
}
@keyframes scroll {
to {
transform: translateZ(0.1px);
}
}
.inner {
display: flex;
height: 100%;
transform: translateX(calc(-100% * var(--index, 0)));
transition: 0.3s;
}
.item {
width: 100%;
height: 100%;
flex-shrink: 0;
display: grid;
place-content: center;
counter-increment: num;
background-color: blueviolet;
color: #fff;
transition: 1s;
transform: translate3d(0, 0, -100px);
/* opacity: 0; */
}
.item::after {
content: counter(num);
font-size: 60px;
}
.item:nth-child(2n + 1) {
background: tomato;
}
.item:nth-child(3n + 2) {
background: royalblue;
}
.item:nth-child(5n + 3) {
background: violet;
}
.item:nth-child(7n + 4) {
background: tan;
color: #333;
}
.item:nth-child(11n + 5) {
background: yellowgreen;
}
view.addEventListener("animationiteration", () => {
const index = getComputedStyle(view).getPropertyValue("--index") || 0;
const len = view.querySelectorAll(".item").length;
if (index == len - 1) {
view.style.setProperty("--index", 0);
} else {
view.style.setProperty("--index", Number(index) + 1);
}
});
This Pen doesn't use any external CSS resources.
This Pen doesn't use any external JavaScript resources.