Javascript 如何在Mootools中管理mouseenter函数中的多个元素?

Javascript 如何在Mootools中管理mouseenter函数中的多个元素?,javascript,mootools,Javascript,Mootools,你好我真的试图在这里找到一个与我的问题相关的主题,但我没有运气 一些简单的代码:我有两个div,放在同一个位置- <div id="fader1" style="display:inline-block;position:absolute;background-image:url(images/fader1.png);opacity:1;width:296px;height:435px;margin:-215px 50px -20px"></div> <div id

你好我真的试图在这里找到一个与我的问题相关的主题,但我没有运气

一些简单的代码:我有两个div,放在同一个位置-

<div id="fader1" style="display:inline-block;position:absolute;background-image:url(images/fader1.png);opacity:1;width:296px;height:435px;margin:-215px 50px -20px"></div>
<div id="fader2" style="display:inline-block;position:absolute;background-image:url(images/fader2.png);opacity:0;width:296px;height:425px;margin:-215px 50px -20px"></div>
如您所见,我只能管理一个元素(this.morph)。我尝试放置其他元素,如:“('fader1').morph”,但没有结果。。。但我认为我做错了


我真的很感谢你能给我的任何帮助来实现这一点在mootools。问候

您应该阅读手册,而不是复制/粘贴示例

$('myElement').set('opacity', 0.5).addEvents({
    mouseenter: function(){
        // This morphes the opacity and backgroundColor
        this.morph({
            'opacity': 0.6,
            'background-color': '#E79D35'
        });
    }
});
在上述函数中,作用域
this
指的是myElement。如果您需要引用不同的元素,那么只需这样做

(function(){
var other = $('myOtherElement').set('moprh', {
    link: 'cancel'
}); // save a reference and set link to cancel existing morphing

$('myElement').set('opacity', 0.5).addEvents({
    mouseenter: function(){
        // This morphes the opacity and backgroundColor
        other.morph({
            'opacity': 0.6,
            'background-color': '#E79D35'
        });
    },
    mouseleave: function(){
        // Morphes back to the original style
        other.morph({
            opacity: 0.5,
            backgroundColor: color
        });
    }
});
}());
阅读$(documentid)返回的内容(元素),将元素保存到变量中并稍后引用它-这是标准javascript

(function(){
var other = $('myOtherElement').set('moprh', {
    link: 'cancel'
}); // save a reference and set link to cancel existing morphing

$('myElement').set('opacity', 0.5).addEvents({
    mouseenter: function(){
        // This morphes the opacity and backgroundColor
        other.morph({
            'opacity': 0.6,
            'background-color': '#E79D35'
        });
    },
    mouseleave: function(){
        // Morphes back to the original style
        other.morph({
            opacity: 0.5,
            backgroundColor: color
        });
    }
});
}());