微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

css原始进度条

CSS原始进度条是一种简单的进度条样式,它直接使用CSS的属性和值对页面元素进行样式处理,不需要使用JavaScript等其他脚本语言,也不需要引入其他插件或库。

progress {
  background-color: #e5e5e5;
  border-radius: 10px;
  height: 15px;
  position: relative;
  overflow: hidden;
}
progress::-webkit-progress-value {
  background-color: #0080ff;
  border-radius: 10px;
  height: 100%;
  position: relative;
  -webkit-animation: progress-bar-stripes 2s linear infinite;
  animation: progress-bar-stripes 2s linear infinite;
}
progress::-moz-progress-bar {
  background-color: #0080ff;
  border-radius: 10px;
  height: 100%;
  position: relative;
  -moz-animation: progress-bar-stripes 2s linear infinite;
  animation: progress-bar-stripes 2s linear infinite;
}
@-webkit-keyframes progress-bar-stripes {
  from {
    background-position: 40px 0;
  }
  to {
    background-position: 0 0;
  }
}
@keyframes progress-bar-stripes {
  from {
    background-position: 40px 0;
  }
  to {
    background-position: 0 0;
  }
}

css原始进度条

上面的代码中,我们定义了一个<progress>元素作为进度条的容器,并对其设置了background-colorborder-radiusheightpositionoverflow等样式属性,使其能够呈现出我们想要的进度条样式。

接着,在<progress>元素的子元素::-webkit-progress-value::-moz-progress-bar中,我们对进度条的进度部分进行了样式定义,如background-colorborder-radiusheightposition-webkit-animation属性,其中-webkit-animationanimation是对动画的设置,让进度条在加载时具有条纹动画效果

最后,我们还定义了两个@keyframes规则,用于控制条纹动画的播放效果

使用CSS原始进度条,能够快速地为页面添加一个简单的进度条,不需要额外的JavaScript代码,更加轻便简洁。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。