![](/img/trans.png)
[英]JQuery stops working when I use AJAX in my script. What am I doing wrong?
[英]Jquery conflict when enqueue script, what am I doing wrong?
我在wordpress安裝中使用磚石結構,它與jquery移動導航插件沖突。 我將砌體代碼保存在.js文件中,然后將其放入函數中。 雖然這是正確的,但我想不是。
在.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' );
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'
});
});
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.