I need to animate a div such that it move left to right and change its color when it hits the edge of screen. So far I have come to a point like this
<div class="move-me">no steps</div>
.move-me {
display: inline-block;
padding: 20px;
color: white;
position: relative;
margin: 0 0 10px 0;
animation: move-in-steps 8s infinite;
}
body {
padding: 20px;
}
@keyframes move-in-steps {
0% {
left: 0;
background: blue;
}
100% {
left: 100%;
background: red;
}
}
where I can smoothly move the div, but the color change is also smooth while I need it to be sharp.
How can I achieve this without using javascript?
2
Answers
Make a very close frame where color is the same for non-smooth color transition. With respect to the edge of the screen, translate the element -100% in the x-axis. Try the following code.
You could put two animations on the element. The second animations just changes the color in the end:
It is not completely sharp at the end but you have to play with the numbers (percentage and seconds).