[前端] 画个圈圈显示百分比

编程入门 行业动态 更新时间:2024-10-08 22:58:20

[前端]   画个圈圈显示<a href=https://www.elefans.com/category/jswz/34/1760575.html style=百分比"/>

[前端] 画个圈圈显示百分比

先看效果

<!DOCTYPE html>
<html>
<head><title></title><meta charset="utf-8"><style type="text/css">@-webkit-keyframes up{0%{top: 0%;}100%{top:-80%;}}@-webkit-keyframes down{0%{top: 0%;}100%{top: 100%;}}/*父元素设置溢出隐藏,设置宽高度,居中,相对定位*/.father{width: 300px;height: 300px;margin:0 auto;overflow: hidden;position: relative;}/*遮罩层给父元素一半的宽度*/.zhe{position: absolute;width: 50%;height:100%;background: #fff;z-index: 100;}/*分别给两个遮罩层添加向上向下走的动画,通过等待时间,实现衔接*/.square_left{left: 0%;top:0px;-webkit-animation:up 1s linear 1s;animation-fill-mode: forwards;}.square_right{left: 50%;top:0px;-webkit-animation:down 1s linear;animation-fill-mode: forwards;}/*设置圈圈的样式*/    .cricle{border:2px solid red;width:296px;height: 296px;border-radius: 50%;z-index: -1}#num{font-size: 26px;color:red;margin:0 auto;z-index: 300;position: absolute;top: 45%;left:45%;}</style></head>
<body >
<div class="father"><div class="cricle"></div><div class="square_left zhe"></div><div class="square_right zhe"></div><div id="num" ></div><script type="text/javascript">var c=0;var t;timedCount();function timedCount(){if (c==81) {clearTimeout(t);return;}document.getElementById('num').innerHTML=c+"%";c=c+1;console.log(t);//开始计时,不断重复这个函数,时间间隔25毫秒;动画是2s,这里2000/80=25ms
    t=setTimeout("timedCount()",25)}</script>
</div>
</body>
</html>

 

转载于:.html

更多推荐

[前端] 画个圈圈显示百分比

本文发布于:2024-02-25 08:28:46,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1698363.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:百分比   圈圈

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!