How can I make masonry and Imagesloaded work correct. (wordpress)

天大地大妈咪最大 提交于 2019-12-08 09:08:28

Ok Made it work. Placed this function in a .js file (change query selector and Itemselector for your own container and the classes inside it):

(function( $ ) {
"use strict";
$(function() {
//set the container that Masonry will be inside of in a var
var container = document.querySelector('.js-masonry');
//create empty var msnry
var msnry;
// initialize Masonry after all images have loaded
imagesLoaded( container, function() {
    msnry = new Masonry( container, {
        itemSelector: '.feed-item'
    });
});
});
}(jQuery));

And then enqueue it in functions.php

wp_enqueue_script( 'masonry' );
wp_enqueue_script( 'jquery' );
wp_enqueue_script( 'masonryInit', get_stylesheet_directory_uri().'/js/masonry.js',      array( 'masonry', 'jquery' ) );
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!