magento使用jquery与noconflict

Leo*_*een 2 jquery conflict magento prototypejs

我正在为我的Magento商店使用2个jquery脚本.其中一个脚本,滑块完美运行,另一个不起作用.

<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>
Run Code Online (Sandbox Code Playgroud)

当我删除jQuery.noconflict(); 这两个脚本都有效但原型脚本不起作用.

这是不起作用的脚本:

jQuery(document).ready(function() {
jQuery('.dropdown').selectbox();}); });</script>
Run Code Online (Sandbox Code Playgroud)

Gow*_*wri 7

你需要在jQuery相关的函数和插件中替换all $(into jQuery($.into jQuery..

例如在你的代码中替换

jQuery('.block_cart_header').hover(function(){
        jQuery('.cart_add_items').fadeIn(700);
    },
    function(){
        jQuery('.cart_add_items').fadeOut(700);
    });
Run Code Online (Sandbox Code Playgroud)

额外的信息

您可以更改库文件启动的顺序.在page.xml中更改顺序如下

  1. 的jquery.js
  2. noconflict.js
  3. prototype.js这将避免IE8中的错误.

希望这可以帮助