Jcarousel and a jquery new added script conflict

旧街凉风 提交于 2019-12-11 05:37:56

问题


There is a conflict with the below code and another jquery code. i fixed another conflict with ajax tabs already using

 jQuery.noConflict();
    jQuery(function ($) {
        // jQuery code in here
    });

but discovered another conflict triggered with jcarousel, doing the same doesn't fixed that issue ,any suggestions will be appreciated.

Jcarousel Code

    <script type="text/javascript" src="{$smarty.const._URL}/js/jquery.jcarousel.pack.js"></script>
          {literal}
          <script type="text/javascript">
  jQuery(document).ready(function() {
   jQuery('#mycarousel').jcarousel({
        size: {/literal}{$total_playingnow}{literal}
    });
  });
  </script>

The new code that triggered conflicts(facebook pop up likebox):

<script type="text/javascript"/>
jQuery.noConflict();
jQuery(function ($) {
//<![CDATA[
jQuery.cookie = function (key, value, options) {

// key and at least value given, set cookie...
if (arguments.length > 1 && String(value) !== "[object Object]") {
options = jQuery.extend({}, options);

if (value === null || value === undefined) {
options.expires = -1;
}

if (typeof options.expires === 'number') {
var days = options.expires, t = options.expires = new Date();
t.setDate(t.getDate() + days);
}

value = String(value);

return (document.cookie = [
encodeURIComponent(key), '=',
options.raw ? value : encodeURIComponent(value),
options.expires ? '; expires=' + options.expires.toUTCString() : '', // use expires attribute, max-age is not supported by IE
options.path ? '; path=' + options.path : '',
options.domain ? '; domain=' + options.domain : '',
options.secure ? '; secure' : ''
].join(''));
}

// key and possibly options given, get cookie...
options = value || {};
var result, decode = options.raw ? function (s) { return s; } : decodeURIComponent;
return (result = new RegExp('(?:^|; )' + encodeURIComponent(key) + '=([^;]*)').exec(document.cookie)) ? decode(result[1]) : null;
};
//]]>

jQuery(document).ready(function($){
if($.cookie('popup_user_login') != 'yes'){
$('#fanback').delay('3000').fadeIn('medium');
$('#fanclose, #fan-exit').click(function(){
$('#fanback').stop().fadeOut('medium');
});
}

});
}); 

回答1:


jQuery(function ($) {
    // jQuery code in here
});

can be changed to

(function($){

    //code here

})(jQuery)

Which should solve conflict issues.



来源:https://stackoverflow.com/questions/20846625/jcarousel-and-a-jquery-new-added-script-conflict

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!