我在wordpress安装中使用砌体,它与jquery移动导航插件冲突。我在.js文件中有Masonry代码,然后将其排入函数中。虽然这是正确的,但我猜不是..
在.js文件中:
(function( $ ) {
"use strict";
$(function() {
//set the container that Masonry will be inside of in a var
var container = document.querySelector('ul.rss-agreggator');
//create empty var msnry
var msnry;
// initialize Masonry after all images have loaded
imagesLoaded( container, function() {
msnry = new Masonry( container, {
itemSelector: 'li.feed-item'
});
});
});
}(jQuery));
我如何将这个脚本排入functions.php:
function wpb_adding_scripts() {
wp_enqueue_script( 'masonry' );
wp_enqueue_script( 'jquery' );
wp_enqueue_script( 'masonryInit', get_stylesheet_directory_uri().'/js/masonry.js', array( 'masonry', 'jquery' ) );
}
add_action( 'wp_enqueue_scripts', 'wpb_adding_scripts' );
答案 0 :(得分:-1)
var $ = jQuery.noConflict();
$(document).ready(function($) {
//set the container that Masonry will be inside of in a var
var container = document.querySelector('ul.rss-agreggator');
//create empty var msnry
var msnry;
// initialize Masonry after all images have loaded
imagesLoaded(container, function() {
msnry = new Masonry(container, {
itemSelector: 'li.feed-item'
});
});
});