Created
April 17, 2023 04:12
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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