desandro / masonry

:love_hotel: Cascading grid layout plugin
https://masonry.desandro.com
16.27k stars 2.11k forks source link

check if all grids have "layoutComplete" #1172

Closed Fanni-Portier closed 2 years ago

Fanni-Portier commented 2 years ago

Is there a way to do something as soon, as all masonry items on the page have triggered the "layoutComplete" event?

Fanni-Portier commented 2 years ago

Asked to soon - sorry!

I found a solution by myself. Maybe another beginner will be looking for this task in the future. So this is how I did it.

var gridLength = $grid.length; var gridCompletet = 0;

$grid.on( 'layoutComplete', function() { gridCompletet++; if ( gridCompletet == gridLength ) { // do something gridCompletet = 0; console.log('all grids are ready'); } });

Fanni-Portier commented 2 years ago

It seems i am unable to format code properly. There is still a lot to learn :D