HTML5技术

SS3可按进度变色的进度条 - jerrylsxu

字号+ 作者:H5之家 来源:博客园 2016-01-14 12:47 我要评论( )

今天是周末,看到一款利用CSS3实现的进度条应用,觉得非常棒,就将它分享给大家,并且将这款CSS3进度条的实现过程大致整理了一下,实现的关键是根据当前的进度需要能改变进度条的背景颜色。下面是效果图: 从外观上来看,这款进度条还是比较优雅的,有jQuery

今天是周末,看到一款利用CSS3实现的进度条应用,觉得非常棒,就将它分享给大家,并且将这款CSS3进度条的实现过程大致整理了一下,实现的关键是根据当前的进度需要能改变进度条的背景颜色。下面是效果图:

从外观上来看,这款进度条还是比较优雅的,有jQuery UI的风格。下面我们来看看具体实现的过程。主要是两部分代码,HTML和CSS3。

HTML代码:

<input type="radio" value="five"> <label for="five">5%</label> <input type="radio" value="twentyfive" checked> <label for="twentyfive">25%</label> <input type="radio" value="fifty"> <label for="fifty">50%</label> <input type="radio" value="seventyfive"> <label for="seventyfive">75%</label> <input type="radio" value="onehundred"> <label for="onehundred">100%</label> <div> <div></div> </div>

主要由两部分,一部分是选择进度的按钮,点击按钮即会让进度条跳转到相应进度的位置并显示对应的背景颜色。

还有一部分HTML则是进度条的容器,进度条就在这个容器中发生各种变化。

CSS3代码:

.container { margin: 80px auto; width: 640px; text-align: center; } .container .progress { margin: 0 auto; width: 400px; } .progress { padding: 4px; background: rgba(0, 0, 0, 0.25); border-radius: 6px; -webkit-box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.25), 0 1px rgba(255, 255, 255, 0.08); box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.25), 0 1px rgba(255, 255, 255, 0.08); } .progress-bar { position: relative; height: 16px; border-radius: 4px; -webkit-transition: 0.4s linear; -moz-transition: 0.4s linear; -o-transition: 0.4s linear; transition: 0.4s linear; -webkit-transition-property: width, background-color; -moz-transition-property: width, background-color; -o-transition-property: width, background-color; transition-property: width, background-color; -webkit-box-shadow: 0 0 1px 1px rgba(0, 0, 0, 0.25), inset 0 1px rgba(255, 255, 255, 0.1); box-shadow: 0 0 1px 1px rgba(0, 0, 0, 0.25), inset 0 1px rgba(255, 255, 255, 0.1); } .progress-bar:before, .progress-bar:after { content: ''; position: absolute; top: 0; left: 0; right: 0; } .progress-bar:before { bottom: 0; background: url("../img/stripes.png") 0 0 repeat; border-radius: 4px 4px 0 0; } .progress-bar:after { z-index: 2; bottom: 45%; border-radius: 4px; background-image: -webkit-linear-gradient(top, rgba(255, 255, 255, 0.3), rgba(255, 255, 255, 0.05)); background-image: -moz-linear-gradient(top, rgba(255, 255, 255, 0.3), rgba(255, 255, 255, 0.05)); background-image: -o-linear-gradient(top, rgba(255, 255, 255, 0.3), rgba(255, 255, 255, 0.05)); background-image: linear-gradient(to bottom, rgba(255, 255, 255, 0.3), rgba(255, 255, 255, 0.05)); }

上面的CSS代码是对进度条的样式进行定义,并采用渐变的CSS3属性来让进度条的背景颜色更加时尚。

接下来是关键的按钮选择进度的CSS代码:

#five:checked ~ .progress > .progress-bar { width: 5%; background-color: #f63a0f; } #twentyfive:checked ~ .progress > .progress-bar { width: 25%; background-color: #f27011; } #fifty:checked ~ .progress > .progress-bar { width: 50%; background-color: #f2b01e; } #seventyfive:checked ~ .progress > .progress-bar { width: 75%; background-color: #f2d31b; } #onehundred:checked ~ .progress > .progress-bar { width: 100%; background-color: #86e01e; } .radio { display: none; } .label { display: inline-block; margin: 0 5px 20px; padding: 3px 8px; color: #aaa; text-shadow: 0 1px black; border-radius: 3px; cursor: pointer; } .radio:checked + .label { color: white; background: rgba(0, 0, 0, 0.25); }

用上面的CSS3代码就可以取代js来实现点击选中的事件,非常方便。

实现的方式大致就是这样,你也可以下载源码自己研究。下载地址>>

 

1.本站遵循行业规范,任何转载的稿件都会明确标注作者和来源;2.本站的原创文章,请转载时务必注明文章作者和来源,不尊重原创的行为我们将追究责任;3.作者投稿可能会经我们编辑修改或补充。

相关文章
  • HTML5动画(二):Canvas 实现圆形进度条并显示数字百分比 - 孟然

    HTML5动画(二):Canvas 实现圆形进度条并显示数字百分比 - 孟然

    2017-02-23 14:05

  • jQuery + CSS3实现环形进度条 - brightest_star

    jQuery + CSS3实现环形进度条 - brightest_star

    2017-02-09 10:01

  • canvas圆形进度条 - 云悠

    canvas圆形进度条 - 云悠

    2016-12-17 11:00

  • HTML5 Canvas玩转酷炫大波浪进度图 - 【当耐特】

    HTML5 Canvas玩转酷炫大波浪进度图 - 【当耐特】

    2016-12-14 11:01

网友点评
t