When using Packery, if I rotate the grid by 45 degrees, the stamped items no longer affect the layout. Why is this happening?
Normally, Packery will layout items around stamped elements. My project is using Packery, but while investigating I discovered that this same issue also occurs in masonry.
I'm rotating the grid using css:
.grid {
transform:rotate(-45deg);
}
You can see an example of the issue on this codepen. As the documentation explains, Packery should lay out item elements around stamped elements (explained here and here).
Any ideas for workarounds would also be helpful.
(Bounty says 90 degrees. It should say 45 degrees (plus or minus)).
It seems like the implicit call to
.layout()
during initialization incorrectly renders rotated stamped objects when the rotation is defined in CSS.Here is a work-around:
.grid
Add the following code after initialization of the grid:
Updated CodePen
Edit - Workaround #2:
To handle responsiveness you can change the JavaScript to the following:
Updated CodePen #2
It looks like any call to
$grid.packery('layout')
after initialization causes problems when the grid is rotated. When the window is resized, it seems like Packery will also recalllayout
. Therefore, the Packery instance needs to be destroyed and recreated for the rotated grid to display correctly on window resize (basically, overriding Packery's responsive functionality).Obviously, this isn't the most ideal solution either - just another workaround.
You may want to open an issue report on their GitHub page for further assistance: https://github.com/metafizzy/packery/issues