栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > Web开发 > Html/CSS > CSS教程

利用css3实现进度条效果及动态添加百分比

CSS教程 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

项目过程中,开始使用了js的requestAnimationframe方法实现进度条,但是在数据超级多的时候非常影响性能,如此改用css去实现,优化。

先贴代码:




    
    
    
    document
    
 *{margin: 0;padding: 0}
 
 .box{width: 100px;height: 10px;border-radius: 10px;background: #999;margin: 100px auto;border: 1px solid #ff6780;}
 .child{position: relative;height:100%;border-radius:inherit;}
 
 .process-animate{background: #ff6780;position: absolute;left: 0;top: 0;bottom: 0;border-radius:inherit;
     animation: process 1s linear forwards ;
 }
 @keyframes process
 {
     0%{
  left:0;right:100%;
     }
     20%{
  right:80%
     }
     40%{
  right:60%;
     }
     60%{right:40%;}
     80%{right:20%;}
     100%{right:0;}
 }
	
    


    
  // child的百分比就是进度条的占比效果
     

效果图(复制代码可查看动态效果):



 正常情况下,百分比肯定是根据后台数据进行计算得出的,所以是动态传入的,下面贴vue代码

进度条子组件(progress.vue):


 

 

.process-wrapper {
  width: 1.98rem;
  height: 0.13rem;
  margin: 0.12rem 0 0.1rem 0;
  border-radius: 0.1rem;
  background: #fff;
  border: 0.01rem solid #ff6780;
  &.addGray {
    background: #999;
    border: 0.01rem solid #999;
  }
  .process-child {
    position: relative;
    height: 100%;
    // width: 100%;  //这个width就是动态变化。通过js改变
    border-radius: inherit;
    .process-animate {
      background: #ff6780;
      position: absolute;
      left: 0;
      top: 0;
      bottom: 0;
      border-radius: inherit;
      animation: process 1s linear forwards;
      &.addGray {
 background: #999 !important;
 // border: 0.01rem solid #999;
      }
    }
  }
}
 
@keyframes process {
  0% {
    left: 0;
    right: 100%;
  }
  20% {
    right: 80%;
  }
  40% {
    right: 60%;
  }
  60% {
    right: 40%;
  }
  80% {
    right: 20%;
  }
  100% {
    right: 0;
  }
}

父组件调用:


 

看看实际效果:



over;完美用css 解决了js递归动画性能消耗。

到此这篇关于利用css3实现进度条效果及动态添加百分比的文章就介绍到这了,更多相关css3进度条添加动态百分比内容请搜索考高分网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持考高分网!

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/214728.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号