JS-2列瀑布流布局
程序员文章站
2022-06-29 08:18:11
js-2列瀑布流布局
window.onload = function () {
var boxarr = $('.indexmsg'),...
js-2列瀑布流布局
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"; }); }
上一篇: 简单学习js
下一篇: 酸菜鱼火锅?不一样的酸菜鱼火锅好吃到哭