magento使用没有冲突的jQuery [英] magento using jquery with noconflict

查看:79
本文介绍了magento使用没有冲突的jQuery的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的Magento商店中使用2个jquery脚本.这些脚本之一,一个滑块可以完美地工作,而另一个则不起作用.

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>

当我删除jQuery.noconflict();时这两个脚本都可以,但是原型脚本不起作用.

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

这是不起作用的脚本:

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

推荐答案

您需要在jQuery相关功能和插件中将所有$(替换为jQuery(,将$.替换为jQuery..

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

例如在您的代码替换中

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

其他信息

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

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 这样可以避免IE8中的错误.
  1. jquery.js
  2. noconflict.js
  3. prototype.js This will avoid the error in IE8.

希望这会有所帮助

这篇关于magento使用没有冲突的jQuery的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆