简体   繁体   English

"如何在引导程序中制作加载进度条?"

[英]How to make a loading progress bar in bootstrap?

I've seen this page from w3school for progress bars.我已经从w3school看到这个页面的进度条。 I am new to bootstrap and for web programming.我是引导程序和网络编程的新手。 It is possible to make it 100% in just 5 seconds?.有可能在短短 5 秒内使其 100% 吗?。 Like a loading progress bar.就像一个加载进度条。

What is a correct way to do it?什么是正确的做法?

Here is a possible solution using twitter bootstrap and jQuery.这是使用 twitter bootstrap 和 jQuery 的可能解决方案。

Fiddler: https://jsfiddle.net/f6hLt9ak/2/提琴手: https : //jsfiddle.net/f6hLt9ak/2/

I have used window.setInterval to set the value for progress-bar every half second.我使用 window.setInterval 每半秒设置一次进度条的值。 Once the progress bar reaches 100%, I am resetting the value back to 0.一旦进度条达到 100%,我就会将该值重置为 0。

HTML: HTML:

<div class="row">
        <div class="col-xs-8">
            <div class="progress">
                    <div class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="width: 0%">
                        0%
                    </div>
                </div>
        </div>
    </div>

JS JS

var progressBar = $('.progress-bar');
var percentVal = 0;

window.setInterval(function(){
    percentVal += 10;
    progressBar.css("width", percentVal+ '%').attr("aria-valuenow", percentVal+ '%').text(percentVal+ '%'); 

    if (percentVal == 100)
    {
        percentVal = 0;      
    }

}, 500);

I hope this code sample will give you an idea on how to proceed at your end.我希望此代码示例能让您了解如何进行最终操作。

If you are confused to add a progress bar.Try automated progress bar如果您对添加进度条感到困惑。尝试自动进度条

Pace.Js佩斯.Js

Pace is really simple to integrate with web pages. Pace 与网页集成非常简单。

Add/Copy Stylesheet on your webpage在您的网页上添加/复制样式表

<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/pace/1.0.2/themes/black/pace-theme-barber-shop.css">

And add JS file并添加JS文件

<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/pace/1.0.2/pace.js"></script>

Sit back Rest of the things Pace will do坐下来 Pace 会做的其他事情

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM