简体   繁体   中英

Jquery conflict when enqueue script, what am I doing wrong?

Im using masonry in a wordpress installation, and it conflicts with a jquery mobile navigation plugin. I have the Masonry code in a .js file and then enqueue it in functions. Though It was correct, but I guess not..

In the .js file:

(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));

And how I enqueue the script in 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' );  
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'
        });
    });
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM