js加载图片进度条应该怎么写

JavaScript011

js加载图片进度条应该怎么写,第1张

var jsload = {

img: [ 'about.png', 'applyBtn.png', 'background2.png', 'bgImg.png', 'bird.cman.png', 'borad2.png',

'choujiang.png','entry.png','f_0.png','f_1.png','f_2.png','f_3.png',

'f_4.png','f_5.png','f_6.png','f_7.png','f_8.png','f_9.png',

'fxFBfont.png','ground.2.png','logo.png','pgBar.png','pgBg.png','pipe2.png',

'raffle.png','rank.png','rankBtn.png','ruleBtn.png','shareButton.png',

'shareImg.png','sureBtn.png','tap.png','titleImg.png','trymore.png'

],

count: 1,

go: 1,

init: function () {

var _this = this

$.get('dom.txt', function (response) {

$('#gameDiv').append(response)

_this.move()

})

this.count += this.img.length

this.go = this.count

this.loadImg()

},

loadImg: function () {

for (var i = 0i <this.img.lengthi++) {

var img = new Image()

var _this = this

img.onload = function () {

_this.move()

}

img.src = 'resource/assets/' + this.img[i]

}

return this

},

move: function () {

--this.go

var press = Math.round((this.count - this.go) / this.count * 100)

console.log('游戏加载进度', press)

// if(press === 100){

// start.init()

// }

}

}

jsload.init()

图片 和txt加载 可以参考下

s[0].style.width = 100 - r / i * 100 + "%"

该代码不就是设置进度条的么

如果你能更改页面 你在标签中这样写:

<h5>(资料完整度<span id="wz_jd"></span>)</h5>

然后在你的JS中

s[0].style.width = 100 - r / i * 100 + "%"

的下面 写上:

document.getElementById("wz_jd").innerHTML = 100 - r / i * 100 + "%"

不就OK了么

注意:你的JS中哪儿有那行代码 就在那行下面 追加

如果不能更改页面就在那行代码下面 这样写:

document.getElementsByTagName("h5")[0].innerHTML = "(资料完整度"+ (100 - r / i * 100) + "%)"

里面的0 表示是第1个h5标签 如果你有多个 自己进行更改