jQuery

【jQuery】CSSとjQueryで構成されたMasonryレイアウトプラグインSALVATTORE

June 11, 2017
SALVATTORE

Salvattoreは、指定した列数に応じてグリッド内の各項目を列に一つずつ内に配置させます。

HOW IT WORKS

<div id="grid" data-columns>
	<div>Item #1</div>
	<div>Item #2</div>
	<div>Item #3</div>
	…
	<div>Item #20</div>
</div>
#grid[data-columns]::before {
	content: '3 .column.size-1of3';
}

/* These are the classes that are going to be applied: */
.column { float: left; }
.size-1of3 { width: 33.333%; }
<div id="grid" data-columns>
	<div class="column size-1of3">
		<div>Item #1</div>
		<div>Item #4</div>
		…
	</div>
	<div class="column size-1of3">
		<div>Item #2</div>
		<div>Item #5</div>
		…
	</div>
	<div class="column size-1of3">
		<div>Item #3</div>
		<div>Item #6</div>
		…
	</div>
</div>

MEDIA QUERIES

@media screen and (max-width: 480px){
	#grid[data-columns]::before {
		content: '1 .column.size-1of1';
	}
}

@media screen and (min-width: 481px) and (max-width: 768px) {
	#grid[data-columns]::before {
		content: '2 .column.size-1of2';
	}
}
@media screen and (min-width: 769px) {
	#grid[data-columns]::before {
		content: '3 .column.size-1of3';
	}
}

/* Again, you’re free to use and define the classes: */
.column { float: left; }
.size-1of1 { width: 100%; }
.size-1of2 { width: 50%; }
.size-1of3 { width: 33.333%; }

MIT