-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Conversation
In Firefox the gutter value is sometimes a bit different. That causes in some use cases a cols calculation result lower than the expected cols result. Using Math.round instead of Math.floor fixes this problem here.
Firefox: operator % produces in some cases results > "1" Safari: operator % produces in some cases "1" as result
@@ -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 ); |
There was a problem hiding this comment.
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.
I appreciate you taking a swing at this, but I don't feel that these edits will work to be merged into master. |
OK, I´ve got it. The thing is, that Math.floor keeps the total width of all cols and gutter within the parent container width. This is a feature so you cannot change this. Thats why Math.round should be used only if there is a miscalculation, may because getting the width from the computed styles. But how to solve this? |
Firefox Jumping Cols BugThe width specified in pixels in the computed styles of the first item element or sizer element with percentage width definition like 33.33333333% or calc( 100% / 3 ) within a fluid element has at certain window widths a greater fractional pixel value than actually physically. In such a case, one column is less calculated than actually would be possible. The effect is, that the amount of calculated cols changes while sizing the layout. Test: http://codepen.io/johannheyne/pen/lCctx A fix could be to floor the columnWidth before it is used. this.columnWidth = Math.floor( this.columnWidth * 100 ) / 100; |
Safari Jumping Cols BugIn Safari there is the same cols jumping effect in fluid layouts with elements in percentage width definition but with another reason. As far as I understand it, this bug is caused on how masonry.js determines to round the calculation of the cols by division of the The script assumes in But Safari just delivers rounded integers for A fix should be consider that in static layouts with static var mathMethod = remainder && ( remainder < 1 ) ? 'round' : 'ceil';
// FIX: Safari Jumping Cols Bug
// if var this.columnWidth is a result of an element with percentage width,
// var mathMethod should be set to 'round'
var colSpan = Math[ mathMethod ]( item.size.outerWidth / this.columnWidth ); |
Will this issue be fixed in the future to easily play with frameworks? |
desandro fixed it in an separate branch |
@desandro Any reason why your overshoot branch has not been merged into master yet? |
I've merged the Thanks again for this contribution. Moving on! 🐎 |
In Firefox the this.gutter value is sometimes a bit different. That causes in some use cases a this.cols calculation result lower than the expected. Using Math.round instead of Math.floor fixes this problem here and outputs the correct this.cols value.
There was a problem in calculation of the colSpan:
Firefox: operator % produces in some cases results > "1"
Safari: operator % produces in some cases "1" as result