【问题标题】:jQuery conflict with MooToolsjQuery 与 MooTools 冲突
【发布时间】:2013-04-05 15:04:04
【问题描述】:
  1. 我创建了幻灯片菜单,如果我使用 MooTools 用光标触摸/不触摸它,它会弹出/弹出://MooTools,http://mootools.net,我的面向对象 (JavaScript) 工具。版权所有 (c) 2006-2009 Valerio Proietti,http://mad4milk.net,麻省理工学院风格许可证。 //core +FX.Scroll +Asset +事件委托

我的脚本的一部分:

window.addEvent('domready', function() {
new SlideoutMenu();



initialize: function()
{
    // FF2 Mac screws up the menu display. give the m the basic menu
    if (Browser.Platform.mac && Browser.Engine.gecko && Browser.Engine.version == 18) {
        $('menu').removeClass('js_live');
        return;
    }

    // iPhone should have normal menu
    if (Browser.Platform.ipod) {
        $('menu').removeClass('js_live');
        return;
    }

    this.bg_div = $('menu');
    this.menu_div = $$('#menu #opts')[0];

    this.logo_lnk = $$('#logo a')[0];
    if (this.logo_lnk.hasClass('home')) {
        this.is_homepage = true;
    }

    var rbsEasing = new Fx.Transition(Fx.Transitions.Expo, 4);      

    this.is_open = false;

    this.bgEffect = new Fx.Tween(this.bg_div, {
        unit: '%',
        property: 'width',
        duration: 650,
        transition: rbsEasing.easeOut,
        onComplete:this.bgEffectComplete.bind(this)
    });

    this.menuEffect = new Fx.Tween(this.menu_div, {
        property: 'left',
        transition: rbsEasing.easeOut,
        duration: 650
    });

    $('logo').addEvent('mouseenter', this.showMenu.bind(this));

    this.mouseBindCallback = this.moveMoveCallback.bind(this);
},

bgEffectComplete: function()
{
    if (this.is_open === false) {
        document.addEvent('mousemove', this.mouseBindCallback);
    }
    this.is_open = !this.is_open;
},

showMenu: function()
{
    if (this.is_open === true) {
        return;
    }

    this.bgEffect.start(70);
    this.menuEffect.start(600, $('logo').getPosition().x);

    this.logo_lnk.addClass('active');

    if (this.is_homepage) {
        this.logo_lnk.removeClass('home');
    }
},

hideMenu: function()
{
    this.bgEffect.start(0);
    this.menuEffect.start(600);

    this.logo_lnk.removeClass('active');

    if (this.is_homepage) {
        this.logo_lnk.addClass('home');
    }
},

moveMoveCallback: function(e)
{
    var close_right = this.menu_div.getPosition().x + 370;
    if (e.page.x > close_right && e.page.y > 80 && this.is_open === true) {
        document.removeEvent('mousemove', this.mouseBindCallback);
        this.hideMenu();
    }
}

菜单没有任何问题,然后

  1. 我使用 jquery 创建了一个照片幻灯片库,当然菜单停止工作。 当我删除 jquery 时,它再次正常工作。 有很多网站说 javascript 和 jquery 之间存在冲突,并且不建议一起使用它们,尽管有一个解决方案

    jQuery.noConflict();应该在

    之后添加

我还在 mooTools 文件 jsc.js 和我自己创建的文件中用 $j 更改了 $。最后它起作用了,但很奇怪,菜单会弹出,但它的元素不再对齐,当我将光标移开时它也不会消失...... 我觉得有一个简单的解决方案,这是因为我在这里缺乏知识,我请求您的帮助

【问题讨论】:

  • "...javascript 和 jquery 之间的冲突" 毫无意义 - jQuery JavaScript 代码。
  • mootools 和 jquery javascript 库冲突

标签: javascript jquery mootools conflict


【解决方案1】:

尝试在您的 mootools 脚本中将所有 $(一美元!不是 2 $$)替换为 document.id

【讨论】:

  • 我用 (function($){ /* 你的类文件在这里 */ })(document.id) 包装了我的 javascript 并且它有效,但谢谢你的建议
【解决方案2】:

没关系,解决了

(function($){ /* your class files here */ })(document.id);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-15
    相关资源
    最近更新 更多