[英]Auto refreshing div jQuery + progress bar loader
I would like to add some progress bar on my auto-refreshing script. 我想在我的自动刷新脚本上添加一些进度条。
Here the script : 这里的脚本:
function update() {
$("#warning").html('Loading..');
$.ajax({
type: 'GET',
url: 'result.php',
timeout: 3000,
success: function(data) {
$("#div_result").html(data);
$("#warning").html('');
window.setTimeout(update, 20000);
},
error: function (XMLHttpRequest, textStatus, errorThrown) {
$("#warning").html('Timeout contacting server..');
window.setTimeout(update, 20000);
}
});
}
$(document).ready(function() {
update();
});
During the "pause" (20sec) I would like to display one progress bar. 在“暂停”期间(20秒),我想显示一个进度条。 Do you have an idea ?
你有想法吗 ?
Just put function progressStatrt(20) before update(); 只需将函数progressStatrt(20)放在update()之前;
http://jsfiddle.net/77udsv9o/3/ http://jsfiddle.net/77udsv9o/3/
CSS: CSS:
#progressbar {
background-color: black;
border-radius: 13px; /* (height of inner div) / 2 + padding */
padding: 3px;
}
#progressbar > div {
background-color: orange;
width: 0%; /* Adjust with JavaScript */
height: 20px;
border-radius: 10px;
}
HTML 的HTML
<div id="progressbar">
<div></div>
</div>
<a id="aStart">START</a>
JS JS
var timeInterval;
var maxSec=0;
var curSec=0;
$(function () {
$('#aStart').click(function(){
progressStatrt(20)//sec. for pause
})
});
function progressStatrt(pauseDurationSec)
{
maxSec=pauseDurationSec;
timeInterval= setInterval(function(){
progessSet()
}, 1000);
}
function progessSet()
{
curSec++;
var proc=100*curSec/maxSec;
$('#progressbar div').width(proc+'%');
if(curSec>=maxSec) progressStop();
}
function progressStop()
{
clearInterval(timeInterval);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.