2012-03-03 16 views
0

これは非常に単純な作業ですが、どこかに間違いがあります。私はそれを見つけることができません。フェーディングが機能しません、JavaScript

function get(obj) { return document.getElementById(obj); } 
var SomeObj = { 
    t1:null,t2:null, 
    hide: function() { 
     if(parseFloat(get("wr_st").style.opacity)>0.45) { 
      get("wr_st").style.opacity-=0.05; 
     } else { 
      clearInterval(SomeObj.t1); 
     } 
    }, 
    show: function() { 
     if(parseFloat(get("wr_st").style.opacity)<1) { 
      get("wr_st").style.opacity+=0.05; 
     } else { 
      clearInterval(SomeObj.t2); 
     } 
    }, 
    fade: function($wt) { 
     if($wt==1) { 
      clearInterval(menu.status.t2); 
      menu.status.t1=setInterval('SomeObj.hide();',10); 
     } else if($wt==2) { 
      clearInterval(menu.status.t1); 
      menu.status.t2=setInterval('SomeObj.show();',10); 
     } 
    } 
} 

私はinput(type = text)を持っています。属性付き:

onfocus="SomeObj.fade(1);" 
onblur="SomeObj.fade(2);". 

オンブラは機能しません。より正確には、これは動作しません:

get("wr_st").style.opacity+=0.05; 

私は例:警告(「NOOOO」)のためにここに配置します場合は、不透明度+ = 0.5が機能しないので、常に処理中です。 あなたは私を助けることができますか:WTFはそれが&なぜ機能しないのですか?ありがとうございます..

+0

'.opacity'を以下のように整数に変換しようとしました:' get( "wr_st")。style.opacity = parseInt(get( "wr_st")。style.opacity)+ 0.05'? – Yaniro

答えて

0

数字を文字列に変換するのではなく、数字を文字列に変換する文字列に数値を追加しています。現在の値が"0.7"の場合は、0.75の代わりに"0.70.05"になります。

は、追加する前に、文字列を解析:

get("wr_st").style.opacity = (parseFloat(get("wr_st").style.opacity) + 0.05).toString(); 

(これはもちろんgetコールを繰り返しているとneccesary以上を解析し、あなたがコード以下repetetive作るためにtempory変数に即時の値を格納することができます)

関連する問題