Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes layout calculation problems for Firefox and Safari #580

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions masonry.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ function masonryDefinition( Outlayer, getSize ) {

this.columnWidth += this.gutter;

this.cols = Math.floor( ( this.containerWidth + this.gutter ) / this.columnWidth );
this.cols = Math.round( ( this.containerWidth + this.gutter ) / this.columnWidth );
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If container width is 800, and columnWidth is 120, then there are only 6 columns, not 7. Using round would round up to 7.

this.cols = Math.max( this.cols, 1 );
};

Expand All @@ -79,7 +79,8 @@ function masonryDefinition( Outlayer, getSize ) {
Masonry.prototype._getItemLayoutPosition = function( item ) {
item.getSize();
// how many columns does this brick span
var remainder = item.size.outerWidth % this.columnWidth;
var factor = item.size.outerWidth / this.columnWidth,
remainder = factor - Math.floor( factor );
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This calculation represents the fractional difference between item.size.outerWidth and columnWidth, not the pixel measurement.

var mathMethod = remainder && remainder < 1 ? 'round' : 'ceil';
// round if off by 1 pixel, otherwise use ceil
var colSpan = Math[ mathMethod ]( item.size.outerWidth / this.columnWidth );
Expand Down