Home > MooTools > [mootools] ロールオーバープラグイン

[mootools] ロールオーバープラグイン

ロールオーバースクリプト(画像名のOn/Offで判別)マウスオーバーでリンク画像の透明度とか変更を足してクラスにしてみた。

指定エリア以下のaタグ拾ってマウスイベントでロールオーバーする。
画像名に指定した文字列があれば置換、なければ透過処理。
ロールオーバーさせない指定はclass名の有無(imgタグ内)で判断する。

Domready

JavaScript:
  1. new wtnRollover({area:"#fontsize"});
  2. new wtnRollover({area:"#main"});

ドル関数は不用で、オプションのareaにID等を指定すること。

Class

JavaScript:
  1. var wtnRollover = new Class({
  2.     Implements: [Options],
  3.     options: {
  4.         area:"body",
  5.         over:"_on",
  6.         off:"_off",
  7.         duration:300
  8.     },
  9.     initialize: function(options) {
  10.         this.setOptions(options);
  11.         this.overTxt = this.options.over;
  12.         this.offTxt = this.options.off;
  13.         this.imgs =  $$(this.options.area + " a img");
  14.         if(this.imgs) this.Roll();
  15.         return true;
  16.     },
  17.     Roll:function(){
  18.         var self = this;
  19.         self.imgs.each(function(img,index){
  20.             if($type(img)=="element"&& !img.hasClass("rollskip")){
  21.                 img.set("tween",{duration: self.options.duration});
  22.                 img.addEvents({
  23.                     "mouseover":function(){
  24.                         if(img.src.indexOf(self.offTxt) === -1)
  25.                             img.tween("opacity",0.5);
  26.                         else
  27.                             img.src = img.src.replace(self.offTxt,self.overTxt);
  28.                         },
  29.                      "mouseleave":function(){
  30.                         if(img.src.indexOf(self.overTxt) === -1 )
  31.                             img.tween("opacity",1);
  32.                         else
  33.                             img.src = img.src.replace(self.overTxt,self.offTxt);
  34.                      }
  35.                 });
  36.             }
  37.         });
  38.     }
  39. });

オプションにduration追加した

thisを変数に格納するとbind(this)しなくてもいいよ、っていう例。

このエントリをはてなブックマークに追加このエントリをdel.icio.usに追加このエントリをLivedoor Clipに追加このエントリをYahoo!ブックマークに追加このエントリをFC2ブックマークに追加このエントリをNifty Clipに追加このエントリをPOOKMARK. Airlinesに追加このエントリをBuzzurl(バザール)に追加このエントリをChoixに追加このエントリをnewsingに追加

Comments:0

Comment Form
Remember personal info

Trackbacks:0

Trackback URL for this entry
http://tenderfeel.xsrv.jp/mootools/344/trackback/
Listed below are links to weblogs that reference
[mootools] ロールオーバープラグイン from WebTecNote

Home > MooTools > [mootools] ロールオーバープラグイン

最近の投稿
最近の修正
  • そしてこのSQLはわれながらよく書いたと思う 2010-11-15
  • CSVの列っていう方がいいのかな…118項目だった 2010-11-15
  • 楽天のCSVの項目が116個もあった衝撃 2010-11-15
  • オフィスで香水臭振りまくのは迷惑だと知れ 2010-11-15
  • ぐあー フレグランステロやー 2010-11-15
  • More updates...

Powered by Twitter Tools

Tag Cloud
おすすめサーバー・他
メタ情報

Return to page top