【问题标题】:How do I convert this snippet to Mootools如何将此代码段转换为 Mootools
【发布时间】:2011-01-23 06:53:47
【问题描述】:

我在这里有一个 Prototype sn-p,我真的很想看到它转换成 Mootools。

document.observe('click', function(e, el) {
    if ( ! e.target.descendantOf('calendar')) {
        Effect.toggle('calendar', 'appear', {duration: 0.4});
    }
});

sn-p 捕捉点击,如果它在容器外点击,$('calendar') 应该切换。

【问题讨论】:

    标签: mootools prototypejs


    【解决方案1】:

    您是否尝试在文档中的任何位置捕捉点击?也许你可以试试……

    var calendar = $('calendar');
    $$('body')[0].addEvent('click', function(e) {
      if (!$(e.target).getParent('#calendar')) {
        var myFx = new Fx.Tween(calendar, {duration: 400});
        myFx.set('display', 'block');
      }
    }
    

    我不确定您是如何切换可见性的,但 Fx.Tween.set 的工作方式允许您更改任何 CSS 属性。您可能想查看http://mootools.net/docs/core/Fx/Fx.Tween 以了解其他可能性。

    另外,请注意我使用 $ 包装了 e.target。这是专门针对 IE 的。我在“Mootools 事件目标”子标题下写了一篇关于 here 的帖子。

    最后,我考虑了 $('calendar') 这样您就不会每次都搜索 DOM。

    【讨论】:

    • 我一回到家就测试一下。看起来它会工作。
    猜你喜欢
    • 1970-01-01
    • 2019-05-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-10-09
    • 1970-01-01
    相关资源
    最近更新 更多