Okay so I'm making a masonry layout style gallery for Wordpress with lazy loading, and lightbox, using Advanced Custom Fields.
I have the lightbox (fancybox-v3) and masonry layout (macy.js) working but when I add in the lazy loading I run into problems. I'm using jQuery.lazy
Here's my loop
<?php
// check if the repeater field has rows of data
if( have_rows('card') ):
// loop through the rows of data
while ( have_rows('card') ) : the_row();
// display a sub field value inside a card
?> <div class="grid-item">
<?php
//VARIABLES//
$title = get_sub_field('card_title');
$childImage = get_sub_field('card_picture');
$file = get_sub_field('card_video');
$video = $file['url'];
// check for image
if( $childImage ): ?>
<a data-fancybox="gallery" data-caption="My caption" href="<?php
echo $childImage['url'];//big one here ?>">
<img class="lazy" data-src="<?php echo $childImage['url']; ?>">
</a>
<?php endif; ?>
//check for video
<?php if( $video ): ?>
<video class="gallery-video" loop autoplay>
<source src="<?php echo $video; ?>" type="video/mp4">
</video
<?php endif; ?>
</div> <?php
endwhile;
else :
// no rows found
endif;
?>
When I run this with jQuery.lazy and macy.js I get a wonky visual result like this:
What you see there at the bottom is a bunch of the images overlapping each other I'm guessing this is because they are being lazy loaded, macy.js doesn't know how to space them out by height.
I don't know how to fix this though? Any suggestions?
Also I found this answer on this question Masonry and Lazy load integration
By klasske that seems to answer, but I'm not sure I understand it (I'm a designer who is new to coding)
Basically Klasske is saying they should create a new function called adjustHeights that they then call inside the options for the jQuery.lazy right? I wasn't clear on that.