I'm looking to create a seamless (no gutters) fullscreen image grid using jquery masonry, where the images are fully responsive and are of varying widths. I've found a couple other starting points out there, but it's proving to be quite difficult for my amount of jquery knowledge.
This is what I'm going for:
http://future.thefutureforward.com/~cycles/assets/images/HUB0002_dAutremont_4WEB.jpg
And this is what I have so far:
http://future.thefutureforward.com/~cycles/archive-test-fluid.html
HTML (just a portion):
<div id="masonry-container">
<div class="box nav-container">
<div id="bumble-bee-sub"><a href="[[~1]]"><img src="assets/img/bumble_bee.png" alt="Cycles d'Autremont" title="Cycles d'Autremont" /></a></div>
<ul id="nav-masonry">
<li><a href="#">Featured</a></li>
<li><a href="#">Process</a></li>
<li><a href="#">Archive</a></li>
<li><a href="#" class="active">Blog</a></li>
</ul>
</div>
<div class="box">
<a href="#">
<img src="assets/images/archive-thumbs/one.jpg" alt="" title="" />
<span class="bike-name"><span>Bicycle #001</span></span>
</a>
</div>
<div class="box">
<a href="#">
<img src="assets/images/archive-thumbs/two.jpg" alt="" title="" />
<span class="bike-name"><span>Bicycle #002</span></span>
</a>
</div>
<div class="box">
<a href="#">
<img src="assets/images/archive-thumbs/three.jpg" alt="" title="" />
<span class="bike-name"><span>Bicycle #003</span></span>
</a>
</div>
</div>
CSS for each "box":
.box{
margin: 0px 0px 0px 0px;
padding: 0px;
float: left;
max-width: 33.3%; /* since we're going for three across... */
}
.box img {
margin: 0px 0px 0px 0px;
padding: 0px;
max-width:100%;
display:block;
}
And here's the jQuery that's doing most the heavy-lifting:
jQuery(document).ready(function($) {
var CollManag = (function() {
var $ctCollContainer = $('#masonry-container'),
collCnt = 1,
init = function() {
changeColCnt();
initEvents();
initPlugins();
},
changeColCnt = function() {
var w_w = $(window).width();
if( w_w <= 600 ) n = 2;
else n = 3;
},
initEvents = function() {
$(window).on( 'smartresize.CollManag', function( event ) {
changeColCnt();
});
},
initPlugins = function() {
$ctCollContainer.imagesLoaded( function(){
$ctCollContainer.masonry({
itemSelector : '.box',
columnWidth : function( containerWidth ) {
return containerWidth / n;
},
isAnimated : true,
animationOptions: {
duration: 300
}
});
});
};
return { init: init };
})();
CollManag.init();
});
It's getting there, but at certain widths it's not filling all of the gaps properly, and smaller screen sizes need some work. If anyone has any tips or thoughts on how to improve this, that would be amazing.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…