I'm working on creating a CSS animation that mimics a slot machine, but I'm struggling to achieve a smooth transition.
.scrollable {
height: 150px;
width: 150px;
margin: 0 auto;
padding: 0;
background: #000;
overflow: hidden;
}
.items {
-webkit-animation: scroll 5s infinite;
-moz-animation: scroll 5s infinite;
-ms-animation: scroll 5s infinite;
}
.number {
color: #ffffff;
font-size: 36px;
padding-bottom: 28px;
position: relative;
top: 20px;
}
@-webkit-keyframes scroll {
0% {
margin-top: 0;
}
27.33% {
margin-top: 0;
}
33.33% {
margin-top: -50px;
}
60.66% {
margin-top: -50px;
}
66.66% {
margin-top: -100px;
}
94.99% {
margin-top: -100px;
}
100% {
margin-top: 0;
}
}
@-moz-keyframes scroll {
0% {
margin-top: 0;
}
27.33% {
margin-top: 0;
}
33.33% {
margin-top: -50px;
}
60.66% {
margin-top: -50px;
}
66.66% {
margin-top: -100px;
}
94.99% {
margin-top: -100px;
}
100% {
margin-top: 0;
}
}
@-ms-keyframes scroll {
0% {
margin-top: 0;
}
27.33% {
margin-top: 0;
}
33.33% {
margin-top: -50px;
}
60.66% {
margin-top: -50px;
}
66.66% {
margin-top: -100px;
}
94.99% {
margin-top: -100px;
}
100% {
margin-top: 0;
}
}
<div class="scrollable">
<div class="items">
<div class="number">1</div>
<div class="number">2</div>
<div class="number">3</div>
<div class="number">1</div>
<div class="number">2</div>
</div>
</div>
How can I create a seamless loop effect instead of the current jarring jump back to the beginning? Also, is there a way to stop the loop after a specific duration, like 30 seconds?