var arrayBKImages = new Array();
arrayBKImages[0] = new Image();
arrayBKImages[1] = new Image();
arrayBKImages[2] = new Image();
arrayBKImages[3] = new Image();
arrayBKImages[4] = new Image();
arrayBKImages[5] = new Image();
arrayBKImages[6] = new Image();
arrayBKImages[7] = new Image();
arrayBKImages[8] = new Image();
arrayBKImages[9] = new Image();
arrayBKImages[10] = new Image();
        imgsCount = arrayBKImages.length;
for(var i=0; i<arrayBKImages.length; i++) {
if (arrayBKImages[i].complete) {
LoadingFn();//显示进度条
} else {
arrayBKImages[i].onload = function() {
LoadingFn();
}
}
} arrayBKImages[0].src = "i0000001.png";
arrayBKImages[1].src = "i0000005.png";
arrayBKImages[2].src = "i0000007.png";
arrayBKImages[3].src = "i0000009.png";
arrayBKImages[4].src = "i0000013.png";
arrayBKImages[5].src = "i0000017.png";
arrayBKImages[6].src = "i0000021.png";
arrayBKImages[7].src = "i0000025.png";
arrayBKImages[8].src = "i0000029.png";
arrayBKImages[9].src = "i0000033.png";
arrayBKImages[10].src = "i0000037.png";
测试发现image.complete属性在火狐下,当第一次加载时为false,刷新的时候为true。不清空缓存是正常的,但是清空缓存后,缓存已经没有这些图片了,complete属性仍为true。结果就是首页被快速打开,但图片仍在一点一点往缓存里加。进度条已经失去真实的意义了。
如果让进度条显示的和清空缓存一样或者和未缓存时一样该怎么做呢?

解决方案 »

  1.   

    测试发现image.complete属性在火狐下,当第一次加载时为false不对吧。。new Image后输出complete属性就是true的,没有false,设置src后才是falsevar a=new Image();
    document.write(a.complete)//true
    a.src='http://static.googleadsserving.cn/pagead/imgad?id=CICAgICQyeLfIhB4GNgEMggliLTa1MMp2w&_dc='+new Date().getTime();
    document.write(a.complete)//false
      

  2.   

    清空缓存,不打开index,这时缓存是空的,刷新几次也都是空的。如果打开index,index快速显示出来,刷新缓存,缓存有几张图片。再刷新,发现图片增加几张,再刷新就又增加几张。
      

  3.   

    arrayBKImages[0].src = "i0000001.png";
    alert(arrayBKImages[0].complete);
    arrayBKImages[1].src = "i0000003.png";
    alert(arrayBKImages[1].complete);
    arrayBKImages[2].src = "i0000005.png";
    alert(arrayBKImages[2].complete);
    arrayBKImages[3].src = "i0000007.png";
    alert(arrayBKImages[3].complete);
    arrayBKImages[4].src = "i0000009.png";
    alert(arrayBKImages[4].complete);
    arrayBKImages[5].src = "i0000011.png";
    alert(arrayBKImages[5].complete);
    arrayBKImages[6].src = "i0000013.png";
    alert(arrayBKImages[6].complete);
    这样写时提示是false。在初次打开Index时。但如果这样写
    arrayBKImages[0].src = "i0000001.png";

    arrayBKImages[1].src = "i0000003.png";

    arrayBKImages[2].src = "i0000005.png";

    arrayBKImages[3].src = "i0000007.png";

    arrayBKImages[4].src = "i0000009.png";

    arrayBKImages[5].src = "i0000011.png";

    arrayBKImages[6].src = "i0000013.png";
    for(var i=0; i<arrayBKImages.length; i++) {
    alert(arrayBKImages[i].complete);
    }
    除了第一个是false外,其他就都是true了。
    在网上查了,是不能把给src赋值的过程放到事件前面的。就是for循环前面的。