如何在html/css/javascript中制作进度条?我不想使用Flash。类似于这里找到的内容:http://dustincurtis.com/about.html
我只需要一个“进度条”,可以根据我在PHP中给出的值进行更改。您会考虑什么?有没有好的教程?
您可以通过控制 div 元素的宽度来实现,使用 CSS。以下是大致的代码:
<div id="container" style="width:100%; height:50px; border:1px solid black;">
<div id="progress-bar" style="width:50%;/*change this width */
background-image:url(someImage.png);
height:45px;">
</div>
</div>
如果需要的话,可以从 PHP 中传入该宽度值。
<progress>
标签。
<progress value="22" max="100"></progress>
或者自己创建一个进度条。
示例使用sencha编写。
if (!this.popup) {
this.popup = new Ext.Panel({
floating: true,
modal: false,
// centered:true,
style:'background:black;opacity:0.6;margin-top:330px;',
width: '100%',
height: '20%',
styleHtmlContent: true,
html: '<p align="center" style="color:#FFFFFF;font-size:12px">Downloading Data<hr noshade="noshade"size="7" style="color:#FFFFFF"></p>',
});
}
this.popup.show('pop');
点击这里查看,或许这正是你需要的。
您可以使用progressbar.js;
来创建动画进度条和小型图表(Sparkline)。
演示和下载链接:链接
HTML用法:
<div id="my-progressbar"></div>
Javascript 的使用方法;
var progressBar;
window.onload = function(){
progressBar = new ProgressBar("my-progressbar", {'width':'100%', 'height':'3px'});
progressBar.setPercent(60);
}
我尝试了一个简单的进度条。它不能被点击,只显示实际百分比。这里有一个很好的解释和代码:http://ruwix.com/simple-javascript-html-css-slider-progress-bar/
<div class="noload">
<span class="loadtext" id="loadspan">50%</span>
<div class="load" id="loaddiv">
</div>
</div>
CSS:
.load{
width: 50%;
height: 12px;
background: url( data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAALCAYAAAC+jufvAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAOwAAADsABataJCQAAABp0RVh0U29mdHdhcmUAUGFpbnQuTkVUIHYzLjUuMTAw9HKhAAAAPklEQVQYV2M48Gvvf4ZDv/b9Z9j7Fcha827Df4alr1b9Z1j4YsV/BuML3v8ZTC/7/GcwuwokrG4DCceH/v8Bs2Ef1StO/o0AAAAASUVORK5CYII=);
-moz-border-radius: 4px;
border-radius: 4px;
}
.noload{
width: 100px;
background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAALCAYAAAC+jufvAAAABGdBTUEAALGPC/xhBQAAAAlwSFlzAAAOwAAADsABataJCQAAABp0RVh0U29mdHdhcmUAUGFpbnQuTkVUIHYzLjUuMTAw9HKhAAAANUlEQVQYVy3EIQ4AQQgEwfn/zwghCMwGh8Tj+8yVKN0d2l00M6i70XsPmdmfu6OIQJmJqooPOu8mqi//WKcAAAAASUVORK5CYII=);
-moz-border-radius: 4px;
border-radius: 4px;
border: 1px solid #999999;
position: relative;
}
.loadtext {
font-family: Consolas;
font-size: 11px;
color: #000000;
position: absolute;
bottom: -1px;
}
Fiddle: 这里
使用纯Javascript实现无限进度条
<div id="container" style="width:100%; height:5px; border:1px solid black;">
<div id="progress-bar" style="width:10%;background-color: green; height:5px;"></div>
</div>
<script>
var width = 0;
window.onload = function(e){
setInterval(function () {
width = width >= 100 ? 0 : width+5;
document.getElementById('progress-bar').style.width = width + '%'; }, 200);
}
</script>
我使用了这个进度条。若想了解更多信息,可以访问这个链接,包括自定义、编码等等。
<script type="text/javascript">
var myProgressBar = null
var timerId = null
function loadProgressBar(){
myProgressBar = new ProgressBar("my_progress_bar_1",{
borderRadius: 10,
width: 300,
height: 20,
maxValue: 100,
labelText: "Loaded in {value,0} %",
orientation: ProgressBar.Orientation.Horizontal,
direction: ProgressBar.Direction.LeftToRight,
animationStyle: ProgressBar.AnimationStyle.LeftToRight1,
animationSpeed: 1.5,
imageUrl: 'images/v_fg12.png',
backgroundUrl: 'images/h_bg2.png',
markerUrl: 'images/marker2.png'
});
timerId = window.setInterval(function() {
if (myProgressBar.value >= myProgressBar.maxValue)
myProgressBar.setValue(0);
else
myProgressBar.setValue(myProgressBar.value+1);
},
100);
}
loadProgressBar();
</script>
希望这对某些人有所帮助。
var myPer = 35;
$("#progressbar")
.progressbar({ value: myPer })
.children('.ui-progressbar-value')
.html(myPer.toPrecision(3) + '%')
.css("display", "block");
height:50px;
。 - HoldOffHunger