所以我有一个包装网格,希望将项目完全整理到容器的高度上...如果宽度关闭,那很好。
查看这样的布局:
<div class="grid">
<div class="grid-item grid-sizer"><img src="http://placehold.it/350x150" border="0" class="img-responsive" /></div>
<div class="grid-item"><img src="http://placehold.it/150x150" border="0" class="img-responsive" /></div>
<div class="grid-item grid-item--width2"><img src="http://placehold.it/700x250" border="0" class="img-responsive" /></div>
<div class="grid-item grid-item--width2"><img src="http://placehold.it/700x200" border="0" class="img-responsive" /></div>
<div class="grid-item"><img src="http://placehold.it/350x150" border="0" class="img-responsive" /></div>
<div class="grid-item"><img src="http://placehold.it/350x150" border="0" class="img-responsive" /></div>
<div class="grid-item"><img src="http://placehold.it/350x150" border="0" class="img-responsive" /></div>
<div class="grid-item grid-item--width2"><img src="http://placehold.it/700x200" border="0" class="img-responsive" /></div>
<div class="grid-item grid-item--width2"><img src="http://placehold.it/700x200" border="0" class="img-responsive" /></div>
<div class="grid-item"><img src="http://placehold.it/350x150" border="0" class="img-responsive" /></div>
<div class="grid-item"><img src="http://placehold.it/150x150" border="0" class="img-responsive" /></div>
<div class="grid-item"><img src="http://placehold.it/350x150" border="0" class="img-responsive" /></div>
<div class="grid-item"><img src="http://placehold.it/350x150" border="0" class="img-responsive" /></div>
</div>
一些一般样式:
.grid-sizer, .grid-item{
width: 20%;
float: left;
img{
width: 100%;
height: auto;
}
}
.grid-item--width2{
width: 40%;
}
最后,发起者:
var $grid = $('.grid').imagesLoaded( function() {
$grid.packery({
columnWidth: '.grid-sizer',
itemSelector: '.grid-item',
gutter: 0,
precentPosition: true
});
});
https://jsfiddle.net/yfp841un/
,所以我决定,如果没有其他jQuery,我可以在以后写的话,如果需要,就必须在上传上规格。没有它,如果有人想让我震惊并向我展示,而不用使用一堆jQuery,我知道可以做到这一点。
但是,混音,我确实写了一件作品,然后将其放回原来,实际上大部分时间都做得很好……仍然有一些空白,直到我标准化了我的规格。
var $grid = $('.grid');
var $gridItems = $grid.children('.grid-item');
$gridItems.sort(function(a, b) {
var tmp = parseInt(Math.random() * 10);
var isOddOrEven = tmp % 2;
var isPosOrNeg = tmp > 5 ? 1 : -1;
return (isOddOrEven & isPosOrNeg);
}).appendTo($grid);
shuffle($gridItems).appendTo($grid);
$('.grid').packery();
function shuffle(array) {
var currentIndex = array.length,
temporaryValue, randomIndex;
// While there remain elements to shuffle...
while (0 !== currentIndex) {
// Pick a remaining element...
randomIndex = Math.floor(Math.random() * currentIndex);
currentIndex -= 1;
// And swap it with the current element.
temporaryValue = array[currentIndex];
array[currentIndex] = array[randomIndex];
array[randomIndex] = temporaryValue;
}
return array;
}