4.16.4 动画样式
在提供了条纹样式以后,Bootstrap还提供了一个更炫的动画样式,即:让条纹动起来。所需要做的只是在进度条容器元素上再多附加一个active样式即可。示例如下:
- <div class="progress progress-striped active">
- <div class="progress-bar" style="width: 45%"></div>
- </div>
实现动画样式的源码如下:
- // 源码4551行
- .progress.active .progress-bar {
- -webkit-animation: progress-bar-stripes 2s linear infinite;/* 2秒过渡40像素,无限循环 */
- animation: progress-bar-stripes 2s linear infinite;/* 其他浏览器 */
- }
上述代码在应用时定义了动画过渡,而通过线性渐变可以看出每40个像素为一个区间,所以该动画过渡也是40个像素,2秒完成,然后无限循环。
不同的浏览器定义的动画过渡的代码如下:
- // 源码4507行
- @-webkit-keyframes progress-bar-stripes { /* Webkit浏览器 */
- from { background-position: 40px 0; }
- to { background-position: 0 0; }
- }
- @keyframes progress-bar-stripes { /* 其他浏览器 */
- from { background-position: 40px 0; }
- to { background-position: 0 0; }
- }
注意
.active样式必须和.progress-striped样式一起应用才行。而IE浏览器只有IE10以上才支持动画过渡效果。