我在 Jquery Isotope 和 Qtip2 之间遇到了严重冲突。当同位素加载时,qtip 不起作用,当它应该激活时,我在 Chrome 控制台中收到 JS 错误:
"Uncaught TypeError: Cannot call method 'call' of undefined" avia.js?ver=1:1326
Avia.js 是我的父主题中一个较大的脚本文件,其中包含完整的同位素。您猜对了,第 1326 行是包含同位素的行。
当我从该文件中删除同位素时,Qtip 工作正常。不幸的是,我现在的情况确实需要两者都工作。
我用我正在使用的所有相同版本设置了一个jsfiddle,并且由于某种原因它可以工作,即使我不遗余力地使用所有相同版本:http://jsfiddle.net/TABd4/8/
这就是我加载脚本的方式。在我的子主题中(使用子主题会出现问题吗?)functions.php:
//Load jquery version
if (!is_admin()) add_action("wp_enqueue_scripts", "my_jquery_enqueue", 11);
function my_jquery_enqueue() {
wp_deregister_script('jquery');
wp_register_script('jquery', get_stylesheet_directory_uri() . '/scripts/qtip/jquery-1.8.3.min.js', false, null);
wp_enqueue_script('jquery');
}
//Enqueue our scripts and stylesheet
function theme_name_scripts() {
wp_enqueue_style('qtip', get_stylesheet_directory_uri() . '/scripts/qtip/jquery.qtip.min.css', null, false, false);
wp_enqueue_script( 'imagesloaded', 'http://cdnjs.cloudflare.com/ajax/libs/jquery.imagesloaded/3.0.4/jquery.imagesloaded.js', null, false, true);
wp_enqueue_script('qtip', 'http://qtip2.com/v/nightly/jquery.qtip.js', array('jquery', 'imagesloaded'), false, true);
wp_enqueue_script( 'qtipscript', get_stylesheet_directory_uri() . '/scripts/qtip/qtipscript.js', array('jquery', 'qtip', 'imagesloaded'), null, true);
}
add_action( 'wp_enqueue_scripts', 'theme_name_scripts' );
这是我运行来触发 qtip (qtipscript.js);
$('.hasTooltip').each(function() { // Notice the .each() loop, discussed below
$(this).qtip({
content: {
text: $(this).next('div') // Use the "div" element next to this for the content
},
style: {
classes: 'qtip-light qtip-shadow qtip-packages'
},
position: {
my: 'top left',
at: 'bottom left',
target: 'event'
}
});
});
最佳答案
找到解决方案:
您需要在同位素脚本之后包含最新版本的 imagesLoaded(3.0.4 对我有用)。就我而言,在加载所有其他脚本后,我只是将脚本硬编码到页脚中,并且解决了问题。
事实证明这是一个已知的冲突,但其页面从未出现在我的 Google 搜索中。 qtip 网站上有更多信息:
关于javascript - WordPress 中的 Qtip2/同位素冲突 : "Uncaught TypeError: Cannot call method ' call' of undefined",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20414005/