magento using jquery with noconflict

荒凉一梦 提交于 2019-11-27 04:52:22

问题


I'm using 2 jquery scripts for my Magento store. One of those scripts, a slider works perfectly and the other one doesnt work.

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

function mycarousel_initCallback(carousel)
{
    // Disable autoscrolling if the user clicks the prev or next button.
    carousel.buttonNext.bind('click', function() {
        carousel.startAuto(0);
    });

    carousel.buttonPrev.bind('click', function() {
        carousel.startAuto(0);
    });

    // Pause autoscrolling if the user moves with the cursor over the clip.
    carousel.clip.hover(function() {
        carousel.stopAuto();
    }, function() {
        carousel.startAuto();
    });
};

jQuery(document).ready(function() {
    jQuery('#mycarousel').jcarousel({
        auto: 0,
        wrap: 'circular',
        animation: 600,
        scroll: 6,
        initCallback: mycarousel_initCallback
    });

    $('.block_cart_header').hover(function(){
        $('.cart_add_items').fadeIn(700);
    },
    function(){
        $('.cart_add_items').fadeOut(700);
    });


});

jQuery(document).ready(function() {
    jQuery('.dropdown').selectbox();
}); });</script>

When I remove jQuery.noconflict(); both of the scripts work but the prototype script doesnt work.

This is the script that doesnt work:

jQuery(document).ready(function() {
jQuery('.dropdown').selectbox();}); });</script>

回答1:


You need to replace all $( into jQuery( and $. into jQuery. in jQuery related functions and plugins.

for example in your code replace

jQuery('.block_cart_header').hover(function(){
        jQuery('.cart_add_items').fadeIn(700);
    },
    function(){
        jQuery('.cart_add_items').fadeOut(700);
    });

Extra information

You may change the order of library file initiating. In page.xml change order as below

  1. jquery.js
  2. noconflict.js
  3. prototype.js This will avoid the error in IE8.

Hope this helps




回答2:


The selectbox plugin is probably using the $ for it's JQuery calls. Change all the $ in the selectbox plugin to jQuery and it should work.

If not, please place a link to the used selectbox plugin.




回答3:


I would guess that the plugin that does not work is the problem. Leave the noConflict on, it is really needed for compatibility between the prototype and jQuery. Check if you are passing a correctly formatted HTML object to the plugin. Probably it expects an object with some specific attributes and those are not present.




回答4:


gowri solution worked for me , if the problem exist again then you need be confirm all the js file that have been used you may missing to check the js files and changed them as stated by "gowri" i.e :

replace all $( into jQuery( and $. into jQuery.


来源:https://stackoverflow.com/questions/8310233/magento-using-jquery-with-noconflict

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