我将砖石与 imagesLoaded 结合起来,如下所示:
var container = document.querySelector('.masonry-container');
var msnry;
// initialize Masonry after all images have loaded
imagesLoaded( container, function() {
var msnry = new Masonry( container, {
itemSelector: '.masonry-item'
}).resize();
});
但出现错误:Uncaught TypeError: Cannot read property 'length' of null
我究竟做错了什么。
编辑
我有两个砌体电话,也许这会导致问题,另一个是相同的,一个接一个:
var container = document.querySelector('.gallery');
var msnry;
// initialize Masonry after all images have loaded
imagesLoaded( container, function() {
var msnry = new Masonry( container, {
itemSelector: '.gallery-item'
}).resize();
});