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

JavaScript012

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加载 可以参考下

<!DOCTYPE "> 

<html xmlns="http://www.w3.org/1999/xhtml" > 

<head> 

<title>进度条</title> 

<style type="text/css"> 

  body{ 

    text-align:center 

  } 

  .graph{ 

    width:450px 

    border:1px solid #F8B3D0 

    height:25px 

  } 

  #bar{ 

        display:block 

        background:#FFE7F4 

        float:left 

        height:100% 

        text-align:center 

    } 

    #barNum{ 

        position:absolute 

    } 

</style> 

<script type="text/javascript"> 

function $(obj){ //封装方法,相当于jQuery

    return document.getElementById(obj) 

function go(){ 

    $("bar").style.width = parseInt($("bar").style.width) + 1 + "%" 

    $("bar").innerHTML = $("bar").style.width 

    if($("bar").style.width == "100%"){ 

        window.clearInterval(bar) //进度为100时清除定时器

    } 

var bar = window.setInterval("go()",50) //设置定时器

window.onload = function(){ 

    bar 

</script> 

</head> 

<body> 

<div class="graph"> 

<strong id="bar" style="width:1%"></strong> 

</div> 

</body> 

</html>

单进图条模式需要进度条长度为1000px的整数倍,

多进度条模式方法就多了,以两根进度条为例来表达的话可以第一根进度条表示1/100的精度,只要长度为100px的整数倍。第二个进度条的精度为1/10,长度需要为10px的整数倍。动画效果为第二根进度条满了第一根进度条进度加1就好了,这样组合起来就可以达到表示1/1000精度的效果。

当然,如果布局有限制直接将值表示在进度条上就行了,前端基本没有多少会刻意的要求动画精度吧。