有一个progressBar 组件。进度数据取自数据库。JS
不推荐使用。
任务是使动画width
从 0 变为当前值(写在 style 属性中)。
每个进度的生成keyframes
- 不太适合。我还想使用一个具有空值的类,当页面加载时,将其删除并使用transition
. 现在我用max-width
. 动画宽度:0->100%,除了动画速度,一切正常。更准确地说,它们是相同的。
实际上问题是:有没有办法做得更好?谢谢大家!
.progress-bar{
width: 500px;
height: 2px;
background: #aaa;
margin: 10px 0;
}
.progress-bar .progress{
background: #f00;
width:100%;
height: 100%;
animation: width100 2s backwards;
}
@keyframes width100{
0% {
width: 0
}
100%{
width: 100%;
}
}
<div class='progress-bar'>
<div class='progress' style='max-width: 75%'></div>
</div>
<div class='progress-bar'>
<div class='progress' style='max-width: 50%'></div>
</div>
<div class='progress-bar'>
<div class='progress' style='max-width: 20%'></div>
</div>