[英]Animate a progress bar without refreshing web page
I am trying to create a progress bar to indicate some dummy statistics on a website. 我正在尝试创建一个进度条,以指示网站上的一些虚拟统计数据。 The values of the progress bar are hard coded.
进度条的值是硬编码的。 I have managed creating the progress bar like this
我已经设法创建了这样的进度条
.progress .progress-bar { box-shadow: none; position: relative; border-radius: 20px; animation: animate-positive 1s; } @keyframes animate-positive { 0% { width: 0; } }
<div class="progress"> <div class="progress-bar" style="width: 60%; background: goldenrod;"> <h3 class="progress-title">Happy Clients</h3> <div class="progress-value">60+</div> </div> </div>
My problem is that this only animates when the page loads and one has to refresh the page to view it again. 我的问题是,这仅在页面加载时进行动画处理,并且必须刷新页面才能再次查看它。 Is there a way I can animate it only when the section is visible?
仅当该部分可见时,是否有办法设置动画?
I hope this is what you are looking for: 我希望这是您要寻找的:
.progress .progress-bar { box-shadow: none; position: relative; border-radius: 20px; animation: animate-positive 1.5s ease 0s alternate infinite none running; } .progress-title{ white-space:nowrap; } @keyframes animate-positive { 0% { width: 0; } 50% { width: 50%; } 100% { width: 0; } }
<div class="progress"> <div class="progress-bar" style="width: 60%; background: goldenrod;"> <h3 class="progress-title">Happy Clients</h3> <div class="progress-value">60+</div> </div> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.