$$('.myclass')[0].fade()
プロトタイプ (および mootools) の $$ は、$$('div#joe')
や $などのあらゆる種類の CSS セレクターを受け入れ$('a[rel=awesome]')
、配列を返します。
$ は、$('joe'); のように ID が一致する要素のみを返します。
したがって、このhtmlを考えると:
<div id="joe" class="awesome"></div>
<div id="sally" class="awesome"></div>
$$('.awesome')
両方の DIV を含む配列を返します
$('joe')
と$$('#joe')
は事実上同じです (後者は配列ですが)。
編集
最初に onclick イベントを削除し、次のように rel 属性にいくつかの情報を追加します。
<a rel="demo" href="#">Div 1</a><br />
<a rel="demo2" href="#">Div 2</a><br />
<a rel="demo3" href="#">Div 3</a>
次に、これをhead
ドキュメントの script タグに入れます。
document.observe("dom:loaded", function() {
// this makes sure the document is loaded and ready to be manipulated
// store your links and demo DIVs in arrays
var links = $$('div.rightcol a');
var demos = $$('.myclass');
// enumerate over the links
links.each(function(link){
// observe the click event of the current link in the loop
link.observe('click',function(event){
event.stop();
// loop the demo DIVs and fade each one
demos.each(function(demo){
demo.fade({ duration: 0.3, from: 1, to: 0 });
});
// figure out which demo to fade in from the links rel attribute
var target = link.readAttribute('rel');
// get the demo target and fade it in
$(target).appear({ delay: 0.35 });
});
});
});
スクリプトが簡単に理解できることを願っています。