您的位置:首页 > 其它

$.ajax的success函数中,监听【多张图片全部加载成功】事件

2015-03-13 23:06 393 查看
<span style="font-style: normal;"><strong>$.ajax({
    url : options.asynOptions.url,
    type : 'post',
    dataType : 'json',
    data : getAjaxData(options.asynOptions.form),
    success : function(data){
        var html = '',
            allow = options.asynOptions.return,
            itemClass = options.itemClass,
            imageClass = options.imageClass,
            count = 0;
        for(var pro in data){
            html += '<div class="'+itemClass+'">';
            html += '<img class="'+imageClass+'" src="'+data[pro][allow[0]]+'" />';
            html += '<span>'+data[pro][allow[1]]+'</span>';
            html += '<span>'+data[pro][allow[2]]+'</span>';
            html += '</div>';
            count++;
        }
        $this.append(html);
        var $colsHeight = [];
        $("."+imageClass).load(function(){
            count--;
            if(count == 0){
                var itemWidth = getFullWith($("."+options.itemClass).eq(0)),
                    cols = getColNumber($this,itemWidth);
                $("."+imageClass).each(function(i,img) {
                    var iheight = getItemFullHeight($("." + itemClass).eq(i));
                    if (i < cols) {
                        $colsHeight[i] = iheight;
                    } else {
                        var minH = Math.min.apply(null, $colsHeight);
                        var minHIndex = $.inArray(minH, $colsHeight);
                        $("." + itemClass).eq(i).css({
                            'position': 'absolute',
                            'top': minH,
                            'left': $(".waterfall_item").eq(minHIndex).position().left
                        });
                        $colsHeight[minHIndex] += iheight;
                    }
                });
            }
        });
    }
});</strong></span>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: