我有一个问题:在我的网站上,按钮“提交”开始在有限的时间内加载一个新页面(以简单的形式定义)。这是完美的工作。我想这样做,当您单击“开始”栏时,会出现并在定义的时间内开始加载。我想使用动画加载 boostrap:
<div class="progress progress-striped active">
<div class="bar" style="width: 40%;"></div>
</div>
我怎样才能做到这一点?Javascript?如何?:(
提前致谢。
总数据: data-percentage="60"
总秒数: data-second="60"
HTML
<div class="progress progress-striped active">
<div class="bar" style="width: 0%;" data-percentage="60" data-second="20"></div>
</div>
<a id="clickme">Click</a>
JS
$('#clickme').click(function () {
var me = $('.progress .bar');
var perc = me.attr("data-percentage");
var sec = me.attr("data-second") * 1000;
var each = sec / perc;
var current_perc = 0;
me.css('width', '100%');
me.text('Loading..');
setTimeout(function () { // Do something after 5 seconds
var progress = setInterval(function () {
if (current_perc >= perc) {
clearInterval(progress);
} else {
current_perc += 1;
me.css('width', (current_perc) + '%');
}
me.text((current_perc) + '%');
}, each);
}, 2000);
});
演示:http: //jsfiddle.net/byybora/XHKkU/4/
加载演示:http: //jsfiddle.net/byybora/dbdAx/43/