Ben*_*wis 2 html javascript twitter-bootstrap
我正在使用Twitter Bootstrap.我需要在30秒后重定向页面.我想使用Twitter Bootstrap Progress Bar指示页面重定向的时间长度(因此当栏处于100%时页面会重定向).请有人帮我使用Javascript和HTML代码来执行此操作.
谢谢 ;)
非常基本的例子:
var bar = document.getElementById('progress'),
time = 0, max = 5,
int = setInterval(function() {
bar.style.width = Math.floor(100 * time++ / max) + '%';
time - 1 == max && clearInterval(int);
}, 1000);
Run Code Online (Sandbox Code Playgroud)
包含在函数中的代码:
function countdown(callback) {
var bar = document.getElementById('progress'),
time = 0, max = 5,
int = setInterval(function() {
bar.style.width = Math.floor(100 * time++ / max) + '%';
if (time - 1 == max) {
clearInterval(int);
// 600ms - width animation time
callback && setTimeout(callback, 600);
}
}, 1000);
}
countdown(function() {
alert('Redirect');
});Run Code Online (Sandbox Code Playgroud)
body {padding: 50px;}Run Code Online (Sandbox Code Playgroud)
<link href="http://getbootstrap.com/2.3.2/assets/css/bootstrap.css" rel="stylesheet"/>
<div class="progress">
<div class="bar" id="progress"></div>
</div>Run Code Online (Sandbox Code Playgroud)