masonry icon indicating copy to clipboard operation
masonry copied to clipboard

masonry calculate right 0% only on FireFox

Open mosijava opened this issue 6 years ago • 6 comments

I use masonry on my site and the problem is : when you open this page on chrome, masonry layout images correctly but in Firefox it only calculate top not right (right is calculated 0% all the time). I initiate masonry with this code:

$('.ArticleImgLightBox').imagesLoaded( function() {
	$(".ArticleImgLightBox").masonry({
		itemSelector: '.lightBoxPic',
		columnWidth: '.lightBox_size',
		percentPosition: true,
		isOriginLeft: false,
		gutter: '.lightbox_gutter_size'
	});
});

am I doing something wrong? or it's bug of masonry.js?

masonry-_FF.jpg

mosijava avatar Jul 18 '18 15:07 mosijava

See #1053 Try to comment out //columnWidth: '.lightBox_size', this fixed the problem for us in Firefox 61.

@desandro I have created a CodePen where yo can see the issue in Firefox 61: https://codepen.io/anon/pen/mjrvPQ

nebrot avatar Jul 19 '18 09:07 nebrot

I think i found the cause of the problem: when using getComputedStyle() to calculate the sizes of the items Firefox (and probably Safari) has changed the behaviour for margins. For non-floating elements the margin-right property is not the defined resolved value but the actual distance from the right border to the right end of the parent element. This means that when masonry calculates the outerWidth of the sizer the result is the full width of the container, so everything gets positioned on one column.

The easy solution i found (which seems to work much better than removing the columnWidth option) is using a float:left; on the sizer element. I have no idea why but with floating elements the value returned by getComputedStyle() is the one you write in the CSS.

Khaash avatar Jul 20 '18 09:07 Khaash

hi @nebrot, thank you, commenting out the columnWidth works fine, but we had used it for a reason. is it safe to remove it permanently?

mosijava avatar Jul 22 '18 15:07 mosijava

commenting out the columnWidth works fine, but we had used it for a reason. is it safe to remove it permanently?

We used it for a reason too..But with this setting it's not working at all. Try the temporary solution of Khaash, it seems to be better than removing the setting.

nebrot avatar Jul 23 '18 07:07 nebrot

Thanks for reporting this issue. I'll have to take a look.

desandro avatar Jul 25 '18 19:07 desandro

I can also confirm that setting float: left; on the our sizer element, when using the columnWidth setting, resolved incorrect column width calculations in Firefox.

morgant avatar Jan 10 '19 18:01 morgant