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

2025-04-06 17:00:32
推荐回答(1个)
回答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 = 0; i < this.img.length; i++) {
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加载 可以参考下