Bootstrap动画进度条

时间:2017-08-18 04:20:34

标签: twitter-bootstrap twitter-bootstrap-3

我厌倦了在boostrap中创建动画进度条,就像下面的图像一样

Progress Bar Needed Output

但是我无法获得正确的输出,我添加了我的Html代码,Javascript代码和& CSS代码

HTML代码

<p class="progress-text">html5</p>
<div class="progress"><div class="progress-bar" data-present="95%"></div></div>
<p class="progress-text">css3</p>
<div class="progress"><div class="progress-bar" data-present="90%"></div></div>

CSS代码

.progress-text{
    text-transform: uppercase;
    color: #333;
    margin-bottom: 5px;
    line-height: 18px;
    font-size: 12px;
}

.progress{
    background-color: transparent;
    border-radius: 0;
    box-shadow: none;
    height: 3px;
    margin-bottom: 15px;
    overflow: visible;
}

.progress:last-child{
    margin-bottom: 0;
}

.progress .progress-bar{
    background: #3f51b5;
    background: transparent -webkit-linear-gradient(left, #3f51b5, #ff4081);
    background: transparent linear-gradient(to right, #3f51b5, #ff4081);
    position: relative;
    -webkit-transition: all 1.5s ease 0.3s;
    transition: all 1.5s ease 0.3s;
    color: inherit;
    opacity: 0;
}

.progress .progress-bar:before{
    position: absolute;
    right: 0;
    content: attr(data-present);
    top: -24px;
    color: inherit;
}

Java脚本代码

(function ($) {
"use strict";
var $progressBar = $('.progress-bar');
$progressBar.appear(function() {
    $progressBar.each(function(){
        var $progressBarWidth = $(this).data('present');
        $(this).css({'width': $progressBarWidth, 'opacity': '1', });
    });
});
})(jQuery); 

Bootstrap版本 3.3.7

Jquery版本 1.12.0

1 个答案:

答案 0 :(得分:0)

.progress-title{
    font-size: 16px;
    font-weight: 700;
    color: #011627;
    margin: 0 0 20px;
}
.progress{
    height: 10px;
    background: #0488cc;
    border-radius: 0;
    box-shadow: none;
    margin-bottom: 30px;
    overflow: visible;
}
.progress .progress-bar{
    box-shadow: none;
    position: relative;
    -webkit-animation: animate-positive 2s;
    animation: animate-positive 2s;
}
.progress .progress-bar:after{
    content: "";
    display: block;
    border: 15px solid transparent;
    border-bottom: 21px solid transparent;
    position: absolute;
    top: -26px;
    right: -12px;
}
.progress .progress-value{
    font-size: 15px;
    font-weight: bold;
    color: #000;
    position: absolute;
    top: -40px;
    right: 0;
}
.progress.pink .progress-bar:after{
    border-bottom-color: #ff4b7d;
}
.progress.green .progress-bar:after{
    border-bottom-color: #5fad56;
}
.progress.yellow .progress-bar:after{
    border-bottom-color: #e8d324;
}
.progress.blue .progress-bar:after{
    border-bottom-color: #3485ef;
}
@-webkit-keyframes animate-positive{
    0% { width: 0; }
}
@keyframes animate-positive{
    0% { width: 0; }
}
<div class="container">
    <div class="row">
        <div class="col-md-6">
            <h3 class="progress-title">HTML5</h3>
            <div class="progress pink">
                <div class="progress-bar" style="width:90%; background:#ff4b7d;">
                    <div class="progress-value">90%</div>
                </div>
            </div>
 
            <h3 class="progress-title">CSS3</h3>
            <div class="progress green">
                <div class="progress-bar" style="width:75%; background:#5fad56;">
                    <div class="progress-value">75%</div>
                </div>
            </div>
        </div>
    </div>
</div>

它只是设计css属性