[英]Javascript Countdown with Twitter Bootstrap Progress Bar
I am working with the Twitter Bootstrap.我正在使用 Twitter Bootstrap。 I need to redirect the page after 30 seconds.我需要在 30 秒后重定向页面。 I want to use the Twitter Bootstrap Progress Bar to indicate how long till the page redirects (So the page redirects when the bar is at 100%).我想使用 Twitter Bootstrap 进度条来指示页面重定向的时间(因此当进度条处于 100% 时页面会重定向)。 Please could someone help me with the Javascript and HTML code to do this.请有人帮助我使用 Javascript 和 HTML 代码来做到这一点。
Thanks ;)谢谢 ;)
Very basic example:非常基本的例子:
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);
Code wrapped in function:封装在函数中的代码:
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'); });
body {padding: 50px;}
<link href="//getbootstrap.com/2.3.2/assets/css/bootstrap.css" rel="stylesheet"/> <div class="progress"> <div class="bar" id="progress"></div> </div>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.