简体   繁体   English

帮助将简单的jQuery转码为mootools

[英]Help transcoding simple jQuery to mootools

$(".container").hover(
     function(){
              $(".child-1").hide(0);
              $(".child-2").show(0);
     },function(){
              $(".child-1").show(0);
              $(".child-2").hide(0);
});

A project I have requires that I use mootools, but I never used mootools, and jquery makes much more sense to me. 我有一个项目要求我使用mootools,但我从未使用过mootools,而jquery对我来说更有意义。 Can someone show me how this example would look like in mootools? 有人可以告诉我这个示例在mootools中的样子吗? thanks 谢谢

MooTools uses two shorthand methods: $ , and $$ MooTools使用两种速记方法: $$$

<div id="someId">..</div>
<p class="someClass">..</p>

Jquery           | MooTools
-------------------------------
$("#someId")     | $("someId")
$(".someClass")  | $$(".someClass");

In MooTools, $ is only used to search elements by ID, and $$ is for everything else. 在MooTools中,$仅用于按ID搜索元素,而$$用于其他所有内容。 So the above can be implemented as: 因此以上可以实现为:

$$(".container").addEvents({
    mouseenter: function() {
        $$(".child-1").hide();
        $$(".child-2").show();
    },
    mouseleave: function() {
        $$(".child-1").show();
        $$(".child-2").hide();
    }
});

.hide() and .show() are shortcut methods that are part of Element.Shortcuts in MooTools-More, but you could define these yourselves if you want. .hide()和.show()是MooTools-More中Element.Shortcuts一部分的快捷方式,但是您可以根据需要自行定义。

But, if you're comfortable with the jQuery syntax and it makes you productive, checkout this project Mooj by Lim Chee Aun. 但是,如果您对jQuery语法感到满意并提高了工作效率,请Mooj Lim Chee Aun的这个Mooj项目。 It allows you to use an almost jQueryish syntax in MooTools. 它允许您在MooTools中使用几乎jQuery的语法。

If you have no particular reason to use only MooTools, checkout how to use MooTools with jQuery on David Walsh's blog. 如果没有特别的理由只使用MooTools,请在David Walsh的博客上查看如何在jQuery中使用MooTools

If you'd like to use jQuery for the DOM and MooTools for the object-oriented goodiness, checkout this article by Ryan Florence. 如果您想将jQuery用于DOM,将MooTools用于面向对象的优点,请查阅Ryan Florence的这篇文章

And finally for a great side-by-side comparison of both frameworks, checkout this definitive article by Aaron Newton. 最后,为了对这两个框架进行详尽的并排比较,请查阅Aaron Newton的这篇权威文章

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM