loading images 加载jquery

2011-05-09 17:47:47 by 【6yang】, 191 visits, 收藏 | 返回

    //loading photo
    jQuery.fn.LoadImage = function(fn){        
        return this.each(function(){
            var src = this.src;
            this.src = '';
            this.onload = function(){
                this.onload = null;
                fn.call(this);
            };
            this.src = src;
        });
    }   

 

//loading photo
    jQuery.fn.LoadImage=function(fn){        
        return this.each(function(){
            var self = $(this);
            var src = self.attr("src");
            var img = new Image();
            img.src = src;
            alert(img.src);
            if(img.complete){
                img.width > 0 ? fn.call(img) : '';                
                return;
            }
            self.attr("src","");
            $(img).load(function(){
                self.attr("src",this.src);
                fn.call(img);
            });
            
        });
    }

分享到:
share

    图片原图

    loading

    loading