jQuery判断背景图片全部加载完成。。

/*var path="http://static.fzbm.com/bmcj/zmjstatic/images/";
        var arr=[
                //path+'img_01.png',
                "http://static.fzbm.com/bmcj/zmjpc/images/header_bag.jpg",
                path+'img_02.png',
                path+'img_03.png',
                path+'img_04.png',
                path+'img_05.png',
                path+'img_06.png',
                path+'img_07.jpg',
                path+'img_08.jpg',
                path+'img_09.png'
            ];*/
        //存放图片
        var f={};
        //存放成功加载图片数量
        var ImgArr=[];
            $(".Imgbg").each(function(i){
                    var _this=$(this);
                    $(this).attr("data-cover",arr[i]);
                    f[i]=new Image();
                    f[i].src=$(this).data("cover");
                    $(f[i]).load(function(){
                            _this.css({
                                    "background-image":"url("+_this.data('cover')+")"
                                })
                                ImgArr.push(f[i]);
                                hasEnd()
                        }) 
                });
            function hasEnd(){
                    if(ImgArr.length===$(".Imgbg").length){
                //当图片都加载完成后执行的方法 init(); } }

 

posted @ 2015-01-30 16:03  开水中的糖  阅读(1011)  评论(0)    收藏  举报