This question is about speed of CSS animation.
.div1{
margin: 10px;
width: 300px;
background: #A1BDAF;
white-space: nowrap;
overflow: hidden;
}
.content{
color: white;
min-width: 100%;
display: inline-block;
animation: moving 4s ease-in-out forwards;
transition: width linear;
}
@keyframes moving{
from{
-webkit-transform: translateX(0);
transform: translateX(0);
margin-left: 0;
}
to{
-webkit-transform: translateX(-100%);
transform: translateX(-100%);
margin-left: 100%;
}
}
<div class = "div1">
<h1 class = "content">
The only thing that matters now is everything You think of me
</h1>
</div>
<div class = "div1">
<h1 class = "content">
I want to fix the speed of running text animation
</h1>
</div>
<div class = "div1">
<h1 class = "content">
regardless of the length of the text.
</h1>
</div>
<div class = "div1">
<h1 class = "content">
Is there any way to set not duration but speed of animation
</h1>
</div>
<div class = "div1">
<h1 class = "content">
with out JavaScript?
</h1>
</div>
As above, the duration of the animation is fixed, so the shorter the text is, the slower the progress, and vice versa. But I want to make the animation speed the same.
In JavaScript, It could be expressible as
sampleDom.style.animationDuration = (sampleDom.scrollWidth) / (speed) +"s";
but I want to write it in CSS without JavaScript.
How to set CSS animation speed the same regardless length of text without JavaScript?