window.onload = function () {
var boxArr = $('.indexmsg'),
columnHeightArr = [];
columnHeightArr.length = 2;
Array.prototype.max=function(){
var maxH = 0;
for(var i=0;i<this.length;i++){
maxH=Math.max(maxH,this[i]);
}
return maxH;
}
boxArr.each(function(index, item) {
if (index < 2) {
columnHeightArr[index] = $(item).outerHeight(true);
} else {
var minHeight = Math.min.apply(null, columnHeightArr),
minHeightIndex = $.inArray(minHeight, columnHeightArr);
$(item).css({
position: 'absolute',
top: minHeight,
left: boxArr.eq(minHeightIndex).position().left
});
columnHeightArr[minHeightIndex] += $(item).outerHeight(true);
}
document.getElementsByClassName("indexmsglist")[0].style.height=columnHeightArr.max()+"px";
});
}
注意:链接jquery库
indexmsglist的position设为relative