jetpack icon indicating copy to clipboard operation
jetpack copied to clipboard

Lazy Images: Layouts using imagesLoaded.js and Masonry.js not working as expected

Open laurelfulford opened this issue 8 years ago • 19 comments

Themes using imageLoaded.js with masonry.js for layouts can end up with gaps and overlaps when Lazy Images are enabled.

Steps to reproduce the issue

  1. Activate a theme using Masonry and imagesLoaded JavaScript libraries for layout. From themes on WP.com, one good option is Baskerville 2.
  2. Make sure Lazy load images are activated.
  3. Make sure you have a number of posts with featured images.
  4. Load the blog posts page.

What I expected

The posts would be displayed evenly spaced, like here: https://baskerville2demo.wordpress.com/

What happened instead

The posts are often further apart, or slightly overlapped. Resizing the browser window will correct the issue.

On page load (note the gaps, and the overlap in the bottom-right corner):

After resizing the browser:

Originally reported for the Opti theme here:

  • 2365-wpcom-premium-themes
  • Follow-up ticket: 1143441-zen.

laurelfulford avatar May 21 '18 18:05 laurelfulford

Similar issue on 4582699-hc. User has a theme using masonry.js. When lazy loading images is enabled, no featured images appear at all:

screen shot 2018-06-25 at 1 50 06 pm

Switching themes fixes the issue.

follow up at 1242521-zen

sdixon194 avatar Jun 25 '18 18:06 sdixon194

Hi @sdixon194! I'm not sure that's the same issue -- the original report was that the masonry layout didn't lay itself out correctly. This sounds a bit different, because the images aren't showing at all.

We ran into something like this with one of our premium themes, where JavaScript in the theme was clashing with lazy loading. Looking at their theme's JS, it already includes its own lazy loading image code -- that could be the culprit!

laurelfulford avatar Jul 21 '18 00:07 laurelfulford

Similar issue is happening with Rebalance, which uses Masonry & imagesLoaded.

  • User report: https://en.forums.wordpress.com/topic/portfolio-thumbnails-overlapping/
  • User's site: https://climbmountains.blog/copywriter-portfolio/
  • Discussion: p1531916072000181-slack-themes

Originally reported here: https://github.com/Automattic/themes/issues/207

laurelfulford avatar Jul 23 '18 21:07 laurelfulford

User reported similar issue here - 5218710-hc

However, I wasn't able to replicate issue on my end but user shared these screenshots - https://sandeepa953175044.files.wordpress.com/2018/07/homepage1.png https://sandeepa953175044.files.wordpress.com/2018/07/homepage2.png https://sandeepa953175044.files.wordpress.com/2018/07/homepage3.png

krutidugade avatar Jul 24 '18 18:07 krutidugade

Hi @krutidugade! Only business & self-hosted sites can enable Lazy Load images separately; looking at that user's site, I think they may be experiencing this theme issue, here: https://github.com/Automattic/themes/issues/208

I've moved the above report over there!

laurelfulford avatar Jul 24 '18 19:07 laurelfulford

@laurelfulford Thank you, I missed it completely!

krutidugade avatar Jul 25 '18 05:07 krutidugade

Also affecting Spatial: https://wordpress.com/themes/spatial

Original trac ticket: https://wpcom-premium-themes.trac.automattic.com/ticket/2464 User-report: 1369452-zen

liviopv avatar Sep 04 '18 15:09 liviopv

Reported again in 1409732-zen, using Baskerville2

I disabled Lazy Load in Jetpack, and the grids seem to have returned to normal.

jesscga avatar Sep 12 '18 15:09 jesscga

reported in 1424789-zen in Garfunkel, Penguin GeneratePress with the upgrade and Cenote. Tested and verified to confirm all that I could.

tmmbecker avatar Sep 18 '18 19:09 tmmbecker

@eliorivero I see you touched this issue in the past, do you know if there are any plans to include a fix in future Jetpack releases?

liviopv avatar Oct 18 '18 07:10 liviopv

Right now there's nothing planned. I'll try to look into this as soon as I have some time.

eliorivero avatar Nov 16 '18 03:11 eliorivero

Any updates? :)

isabellachen avatar Dec 06 '18 12:12 isabellachen

Also reported in 1625283-zen with smartblog theme. cc: @isabellachen

joeboydston avatar Dec 06 '18 12:12 joeboydston

Another repport here: 9661791-hc with the Ippo theme . Disabling lazy load worked.

mlaetitia avatar Jan 23 '19 09:01 mlaetitia

Similar issue here HC-9796665

rossanafmenezes avatar Jan 28 '19 11:01 rossanafmenezes

Is there an event triggered in Jetpack's Lazy Load? If so imagesLoaded and/or Masonry can rebuilt itself.

Update: listen for the jetpack-lazy-loaded-image Lazy Images event and rebuild your Masonry.

$(document.body).on('jetpack-lazy-loaded-image', function () {
    // Example of my $blocks variable (you'll have to update the classes to match your theme/html)
    // var $blocks = $('.two-column .gallery-wrapper,.three-column .gallery-wrapper');
    $blocks.imagesLoaded(function () {
      $blocks.masonry('reloadItems').masonry('layout');
    });
});

thefrosty avatar Feb 03 '19 19:02 thefrosty

@thefrosty where does this code go?

isabellachen avatar Feb 04 '19 09:02 isabellachen

@isabellachen you can put it anywhere you like. If you're theme allows custom JS in the settings page, or if you have access to a custom JS file in a functionality plugin etc.

thefrosty avatar Feb 04 '19 17:02 thefrosty

Actual for the external theme: https://wordpress.org/themes/minimal-grid/

1988452-zen

tgglv avatar Apr 26 '19 14:04 tgglv