即使使用$ .noConflict(),2个jquery库仍然存在冲突;

时间:2014-06-27 13:22:13

标签: javascript jquery wordpress shared-libraries conflict

我无法理解为什么我的主题仍然与我在网上找到的JS相冲突。

我的主题是来自(http://onioneyethemes.com/yin-yang/

的yin yang

我试图运行的主题是引用旋转器,我将把代码放在这里,因为它的网站从昨天起就停止了:

/*
 * jQuery Quovolver v1.0 - http://sandbox.sebnitu.com/jquery/quovolver
 *
 * By Sebastian Nitu - Copyright 2009 - All rights reserved
 * 
 */

(function($) {
    $.fn.quovolver = function(speed, delay) {

        /* Sets default values */
        if (!speed) speed = 500;
        if (!delay) delay = 6000;

        // If "delay" is less than 4 times the "speed", it will break the effect 
        // If that's the case, make "delay" exactly 4 times "speed"
        var quaSpd = (speed*4);
        if (quaSpd > (delay)) delay = quaSpd;

        // Create the variables needed
        var quote = $(this),
            firstQuo = $(this).filter(':first'),
            lastQuo = $(this).filter(':last'),
            wrapElem = '<div id="quote_wrap"></div>';

        // Wrap the quotes
        $(this).wrapAll(wrapElem);

        // Hide all the quotes, then show the first
        $(this).hide();
        $(firstQuo).show();

        // Set the hight of the wrapper
        $(this).parent().css({height: $(firstQuo).height()});       

        // Where the magic happens
        setInterval(function(){

            // Set required hight and element in variables for animation
            if($(lastQuo).is(':visible')) {
                var nextElem = $(firstQuo);
                var wrapHeight = $(nextElem).height();
            } else {
                var nextElem = $(quote).filter(':visible').next();
                var wrapHeight = $(nextElem).height();
            }

            // Fadeout the quote that is currently visible
            $(quote).filter(':visible').fadeOut(speed);

            // Set the wrapper to the hight of the next element, then fade that element in
            setTimeout(function() {
                $(quote).parent().animate({height: wrapHeight}, speed);
            }, speed);

            if($(lastQuo).is(':visible')) {
                setTimeout(function() {
                    $(firstQuo).fadeIn(speed*2);
                }, speed*2);

            } else {
                setTimeout(function() {
                    $(nextElem).fadeIn(speed);
                }, speed*2);
            }

        }, delay);

    };
})(jQuery);

我很确定它不起作用的原因是主题js与反向链接到jquery的冲突

删除此内容:

    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.1/jquery.min.js"></script>

会使我的主题有效。并且添加(旋转器的要求)将禁用我的主题的效果。

以下是我尝试消除冲突的方法:

    <script type="text/javascript">
    $.noConflict();
    $(document).ready(function() {

        $('blockquote').quovolver();

    });
</script>

但仍然没有运气。有谁可以帮我解决冲突?

1 个答案:

答案 0 :(得分:1)

试试这个

 jQuery(document).ready(function($){
        // You can then use `$` inside this func,
        // it will not show errors now
        $('blockquote').quovolver();  
    });

$.noConflict(true);