两个 jQuery 脚本之间的冲突

发布于 2024-11-03 01:23:55 字数 1289 浏览 1 评论 0原文

我是西班牙人(抱歉我的英语),这是我第一次在这里写信询问一些事情。

经过几个小时的调试和搜索 Fancybox 脚本不起作用的原因后,我在我的网站上搜索了两个脚本之间的冲突(现在处于维护模式),

我在我的网站上使用了一些脚本,但我可以肯定地说我之间存在冲突这两个脚本:

http://www.planetdescargas.com/wp-content/themes/bigfoot/javascripts/jquery.mousewheel-3.0.4.pack.js    
http://www.planetdescargas.com/wp-content/themes/bigfoot/javascripts/jquery.fancybox-1.3.4.pack.js

AND

http://www.planetdescargas.com/wp-content/plugins/buddypress/bp-themes/bp-default/_inc/global.js?ver=3.0.5

前两个脚本是jquery插件“fancybox”,另一个是主要的javascript(Ajax ) 对于 WordPress 插件:巴迪出版社。

后者在 fancybox 中造成冲突。如果我删除 BuddyPress 的脚本,fancybox 可以正常工作,但如果没有,fancybox 将无法工作。

BuddyPress 的脚本 global.js 在一开始就定义了一个变量,该变量是生成脚本的变量。 我尝试这样定义它:

var jq = jQuery.noConflict ();

但仍然不起作用。

有什么建议吗?

在 Firebug 控制台中我得到了这个:

c.easing[this.options.specialEasing && this.options.specialEasing[this.prop] || a] is not a function

[Detener en este error] e,this.options.orig[e]);this.options.c...++)ab||a.splice(b--,1); a.长度||

第 143 行

http://www.planetdescargas.com/wp-includes/js/jquery/jquery.js?ver=1.4.2

致谢

I'm spanish (sorry for my english), and it's the first time that i write here for ask something.

After hours of debugging and searching why the Fancybox script didn't work i search a conflict between two scripts in my website (now in Maintence Mode)

I use a few scripts on my website, but I can safely say that I have a conflict between these two scripts:

http://www.planetdescargas.com/wp-content/themes/bigfoot/javascripts/jquery.mousewheel-3.0.4.pack.js    
http://www.planetdescargas.com/wp-content/themes/bigfoot/javascripts/jquery.fancybox-1.3.4.pack.js

AND

http://www.planetdescargas.com/wp-content/plugins/buddypress/bp-themes/bp-default/_inc/global.js?ver=3.0.5

The first two scripts is the plugin for jquery "fancybox", the other is the main javascript (Ajax) for wordpress plugin: BuddyPress.

The latter creates conflict in fancybox. If I remove BuddyPress' script, fancybox works perfectly, but if not, fancybox don't work.

BuddyPress' script, global.js has a variable defined at the outset that is the one that makes the script.
I try to define it this way:

var jq = jQuery.noConflict ();

But still not working.

Any suggestions?

In Firebug console i got this:

c.easing[this.options.specialEasing && this.options.specialEasing[this.prop] || a] is not a function

[Detener en este error] e,this.options.orig[e]);this.options.c...++)ab||a.splice(b--,1);a.length||

Line 143 of

http://www.planetdescargas.com/wp-includes/js/jquery/jquery.js?ver=1.4.2

Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

陈甜 2024-11-10 01:23:55

只需使用这种方式即可。

打开 wp-content/plugins/buddypress/bp-themes/bp-default/_inc/global.js

在顶部添加:

jQuery.noConflict (jquery_working =! html bind);

转到行 #1264
添加如下:

;(function(jQuery){  ///Add this before start jQuery.easing.
  jQuery.easing.jswing=jQuery.easing.swing;jQuery.extend(jQuery.easing, {def:"easeOutQuad",swing:function(e,f,a,h,g){return ......
  // ...
})(jQuery); //Add this end of the call.

同样可以解决 jQuery Cookie 插件冲突错误。

Simply use this way.

Open the wp-content/plugins/buddypress/bp-themes/bp-default/_inc/global.js

Add on top:

jQuery.noConflict (jquery_working =! html bind);

Go to line #1264
Add this below:

;(function(jQuery){  ///Add this before start jQuery.easing.
  jQuery.easing.jswing=jQuery.easing.swing;jQuery.extend(jQuery.easing, {def:"easeOutQuad",swing:function(e,f,a,h,g){return ......
  // ...
})(jQuery); //Add this end of the call.

Similarly you can resolve the jQuery Cookie plugin conflict error.

看海 2024-11-10 01:23:55

这不是您使用 jQuery.noConflict() 的方式。 noConflict() 释放对 $ 符号的控制。从我从您的其他脚本中看到的情况来看,它们使用安全的方式 ((function($){ }(jQuery))) 因此使用 noConflicts() 没有实际的影响。

把它改成

var jq = jQuery.noConflict ();

这样:

jQuery.noConflict ();
var jq = jQuery;

为了确定。

文档: http://api.jquery.com/jQuery.noConflict/

That's not how you use jQuery.noConflict(). noConflict() releases control of the $ symbol. From what I see from your other scripts though, they use the safe way ((function($){ }(jQuery))) so using noConflicts() has no actual effect.

Change this

var jq = jQuery.noConflict ();

into this:

jQuery.noConflict ();
var jq = jQuery;

To make sure.

Documentation: http://api.jquery.com/jQuery.noConflict/

千仐 2024-11-10 01:23:55

我不知道出了什么问题,但我解决了问题。我在主题根目录的functions.php中使用此代码:

    function fancybox_js() {
            wp_enqueue_script('jquery.fancybox', 'http://www.planetdescargas.com/wp-content/themes/bigfoot/javascripts/fancybox/jquery.fancybox-1.3.4.pack.js', array('jquery'), '1.3.4');
            wp_enqueue_script('jquery.easing', 'http://www.planetdescargas.com/wp-content/themes/bigfoot/javascripts/fancybox/jquery.easing-1.3.pack.js', array('jquery'), '1.3');
            wp_enqueue_script('jquery.mousewheel', 'http://www.planetdescargas.com/wp-content/themes/bigfoot/javascripts/fancybox/jquery.mousewheel-3.0.4.pack.js', array('jquery'), '3.0.4');
    }

add_action('wp_enqueue_scripts', 'fancybox_js', 999); 

我从名为 Easy Fancybox,现在一切正常。谢谢!

I don't know what was wrong, but i solved the problem. I use this code in my functions.php in my theme root:

    function fancybox_js() {
            wp_enqueue_script('jquery.fancybox', 'http://www.planetdescargas.com/wp-content/themes/bigfoot/javascripts/fancybox/jquery.fancybox-1.3.4.pack.js', array('jquery'), '1.3.4');
            wp_enqueue_script('jquery.easing', 'http://www.planetdescargas.com/wp-content/themes/bigfoot/javascripts/fancybox/jquery.easing-1.3.pack.js', array('jquery'), '1.3');
            wp_enqueue_script('jquery.mousewheel', 'http://www.planetdescargas.com/wp-content/themes/bigfoot/javascripts/fancybox/jquery.mousewheel-3.0.4.pack.js', array('jquery'), '3.0.4');
    }

add_action('wp_enqueue_scripts', 'fancybox_js', 999); 

I took the libraries from a wordpress plugin called Easy Fancybox, and now all work fine. Thanks!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文