Skip to content

Instantly share code, notes, and snippets.

@Archie22is
Created April 17, 2023 04:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Archie22is/aa87309375dc7f536233c1db534c3d20 to your computer and use it in GitHub Desktop.
Save Archie22is/aa87309375dc7f536233c1db534c3d20 to your computer and use it in GitHub Desktop.
Fix gap on a Wordpress theme, which uses jetpack masonry and imagesloaded lazyload.
/**
* Add or try this in file masonryInitializer.js
* Source: https://github.com/desandro/imagesloaded/issues/303
*
*/
(function ($) {
"use strict";
$(document).ready(function () {
// init Masonry
var $grid = $('.msnry-grid').masonry({
itemSelector: '.msnry-grid-item',
columnWidth: '.msnry-grid-sizer',
percentPosition: true,
});
// layout Masonry after each image loads
$grid.find('[loading="lazy"]').on('load', function() {
$('.msnry-grid').masonry('layout');
})
});
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment