带有 Twitter Bootstrap 进度条的 Javascript 倒计时

标签 javascript html 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);

封装在函数中的代码:

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>

关于带有 Twitter Bootstrap 进度条的 Javascript 倒计时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14910762/

相关文章:

html - XSL : set image src using attribute 中的引号

css - Bootstrap 中页面底部的元素

javascript - 将组件渲染到摘要行

javascript - 根据 PHP 输出更改 Javascript src

javascript - 将数据加载到 HTML 中的可变高度表

jquery - HTML 标签式滑动

javascript - Bootstrap 4 个嵌套选项卡 : 'show all' button to display nodes in sub-tabs

javascript - 使用 get/set 定义一个属性,其行为类似于普通属性

javascript - 如何将所选项目传递给 axios

javascript - HTML5 : Input Type File - read image data