js 对加载图片的判断

var IE=navigator.appName=="Microsoft Internet Explorer";
var Opera=navigator.appName.toLowerCase()=="opera";
var FF=!IE && !Opera;

function loaderFunction(style,num,iframe_width,iframe_height) {
    this._preImages = new Array();

    this._imageUrlBuffer = new Array();
    this._currentID = 0;
    this._loaded = new Array();
    this._loadedNum = 0;
    this._currentLoading = "";
    this._timeOut = 2 * 1000;
    this._timeElapsed = 0;
    this._checkInterval = 50;
    this._style = style;
    this._num = num;
    this._iframe_height = iframe_height;
    this._iframe_width = iframe_width;
    this._loadok = new Array();

}
loaderFunction.prototype.add = function() {

    for (var i = this._currentID; i < arguments.length; this._currentID++,i++) {
        if (arguments[i] != null || arguments[i] != "") {
            this._imageUrlBuffer[i] = arguments[i];
        }
    }
}
loaderFunction.prototype.getResourceCount = function() {
    return this._imageUrlBuffer.length;
}
loaderFunction.prototype.getLoadedCount = function() {
    return this._loadedNum;
}
loaderFunction.prototype.getCurrentLoading = function() {
    return this._currentLoading;
}
loaderFunction.prototype.setTimeOut = function(ts) {
    this._timeOut = ts;
}
loaderFunction.prototype.getTimeOut = function() {
    return this._timeOut;
}
loaderFunction.prototype.startLoad = function() {
    for (var i = 0; i < this._imageUrlBuffer.length; i++) {
        this._preImages[i] = new Image();
        var test = new Image();
       
        if(FF)
        {
            this._preImages[i].onload = this.loading(i);
        }
        this._preImages[i].src = this._imageUrlBuffer[i];
        this._loaded[i] = false;
    }
    this.checkLoad();
}
if(FF)
{
    loaderFunction.prototype.loading = function(k)
    {
        this._loadok[k] = 1;

    }
}
loaderFunction.prototype.checkLoad = function() {
    if (this._loadedNum == this._preImages.length) {
        this.onLoadFinish();
        return;
    }
    if (this._timeElapsed >= this._timeOut) {
        this.onTimeOut();
        return;
    }
    for (i = 0; i < this._preImages.length; i++) {
        if(FF)
        {
            if (this._loaded[i] == false && this._loadok[i] == 1 && this._preImages[i].height == 50) {

                this._loaded[i] = true;
                this._currentLoading = this._imageUrlBuffer[i];
                this._loadedNum++;
                this.onProgressChange();
            }
        }
        else
        {
            if (this._loaded[i] == false && this._preImages[i].complete) {

                this._loaded[i] = true;
                this._currentLoading = this._imageUrlBuffer[i];
                this._loadedNum++;
                this.onProgressChange();
            }
        }
    }
    this._timeElapsed += this._checkInterval;
    setTimeout("a"+this._style+".checkLoad()",this._checkInterval);
}
loaderFunction.prototype.onProgressChange = function() {
    ;
}
loaderFunction.prototype.onLoadFinish = function() {
    document.getElementById("d"+this._style).innerHTML=DilinglingShowad(this._style,this._num,this._iframe_width,this._iframe_height);
}
loaderFunction.prototype.onTimeOut = function() {
    //alert("timeout!");
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值