我最近问过如何使用进度条,没有人回答所以我编写了一个自定义进度条,它完美但是[]扩展了每个新的增量,这是由于字体宽度?还是可以修复?我使用了
,因为它首先会扩展。
<script type="text/javascript">
var imgsb = new Array("[/ ]","[// ]","[/// ]","[//// ]","[///// ]","[///// ]","[////// ]","[/////// ]","[//////// ]","[///////// ]","[///////// ]","[////////// ]","[/////////// ]","[//////////// ]","[///////////// ]","[////////////// ]","[/////////////// ]","[//////////////// ]","[///////////////// ]","[////////////////// ]","[/////////////////// ]","[//////////////////// ]","[///////////////////// ]","[////////////////////// ]","[///////////////////////]");
altb = new Array();
var currentAdb = 0;
var imgCtb = 25;
function cycleb() {
if (currentAdb == imgCtb) {
currentAdb = 0;
}
document.getElementById('adLinkb').innerHTML = imgsb[currentAdb];
currentAdb++;
}
window.setInterval("cycleb()",500);
</script>
<div style="font-size:12px;color:#fff;font-family:monospace;" id="adLinkb">[/ ]</div>
答案 0 :(得分:2)
看看它有多清洁:
var currentAdb = 0;
var imgCtb = 25;
function cycleb() {
var output = '[';
for (var i = 0; i < imgCtb; i++) {
output += i > currentAdb ? ' ' : '/';
}
output += ']';
document.getElementById('adLinkb').innerHTML = output;
++currentAdb;
if(currentAdb == imgCtb) {
window.clearInterval(myInterval);
}
}
var myInterval = window.setInterval(cycleb, 500);
&#13;
#adLinkb {
font-size: 12px;
color: #000;
font-family: monospace;
}
&#13;
<div id="adLinkb"></div>
&#13;
答案 1 :(得分:0)
@Dave Goten回答了这个问题 谢谢大家的帮助。
<script type="text/javascript">
var imgsb = new Array("[/ ]","[// ]","[/// ]","[//// ]","[///// ]","[///// ]","[////// ]","[/////// ]","[//////// ]","[///////// ]","[///////// ]","[////////// ]","[/////////// ]","[//////////// ]","[///////////// ]","[////////////// ]","[/////////////// ]","[//////////////// ]","[///////////////// ]","[////////////////// ]","[/////////////////// ]","[//////////////////// ]","[///////////////////// ]","[////////////////////// ]","[///////////////////////]");
altb = new Array();
var currentAdb = 0;
var imgCtb = 25;
function cycleb() {
if (currentAdb == imgCtb) {
currentAdb = 0;
}
document.getElementById('adLinkb').innerHTML = imgsb[currentAdb];
currentAdb++;
}
window.setInterval("cycleb()",500);
</script>
<div style="font-size:12px;color:#fff;font-family:monospace;" id="adLinkb">[/ ]</div>