javascript - jQuery Masonry breaking randomly at certain widths -
i'm using jquery masonry develop responsive grid of photos. i'm using simple css proportional grid, , works fine (other fact floats don't work vertically). moment add masonry layout breaks.
$(document).ready(function() { // select container var $work = $(".work"); // set columns based on window width var columns = 3, setcolumns = function() { columns = $(window).width() > 768 ? 3 : 2; }; $work.imagesloaded(function() { $work.masonry({ itemselector: '.project', columnwidth: function(containerwidth) { return containerwidth / columns; } }); $(window).on('resize', function() { // set columns browser width different. setcolumns(); $work.masonry('reload'); }).resize(); }); }); a jsfiddle demonstrating issue can found here.
above 768px breakpoint, things work (albeit lots of flickering), below break point should 2 columns fits one.
fixes i've tried:
- setting columnwidth 1 fixes in safari , firefox, not chrome.
- setting width of 1 of columns 47.5% instead of 49% (which accounts 1 2% margin), grid doesn't line visually.
i suspect it's widths , margins being ever over, i've checked code thoroughly , numbers should add nice 100% width. it's when masonry comes in breaks.
thoughts? appreciated.
set margins 0 , masonry should fit together. here demo:
/* basic grid structure */ .half, .third, .two-third, .quarter { float: left; margin: 0; } .two-third + .third, .third:nth-child(3n+0), .quarter:nth-child(4n+0) { margin: 0 0 0 0; } .half:nth-child(2n+0), .third:nth-child(3n+0), .quarter:nth-child(3n+0) { margin-right: 0; }
Comments
Post a Comment