2012-01-17 3 views
0

パラメータをオプションにする必要があります。それが意味をなさないならば。JavaScriptがパラメータの場合、画像の透明度を無視する

私の両方の機能が同じであることに気がついたら、私はこの違いをパラメータに変える必要があります。新しいパラメータクラスI //ここに私のコード

//get the element under the mouse, ignoring all transparency. 
function getElement(x, y){ 
    var elem = document.elementFromPoint(x, y); 
    if($(elem).parents("#game").length != 1){ return -1; } 
    var pixelAlpha = mousePixelOpacity(elem, x, y); 
    var track = Array; 
    for(var i = 0;i<50;i++){ 
    if($(elem).attr("id") == "game"){ return -1;} 
    if(pixelAlpha == 0){ /////////////////////////////////////////HERE 
     track[i] = elem; 
     for(var z = 0; z<i+1; z++){ //hide elements 
     $(track[z]).hide(); 
     } 
     elem = document.elementFromPoint(x, y); //set the element right under the mouse. 
     pixelAlpha = mousePixelOpacity(elem, x, y); 
     for(var z = 0; z<i+1; z++){ //show all the recently hidden elements 
     $(track[z]).show(); 
     } 
    } 
    if(pixelAlpha != 0){ ///////////////////////////////////////// AND HERE 
     return elem; 
    } 
    } 
    return -1; 
} 

//get the tile under the mouse, even if it's behind an object 
function getTile(x, y){ 
    var elem = document.elementFromPoint(x, y); 
    if($(elem).parents("#game").length != 1 && $(elem).attr("id") != "tileHighlight"){ return -1; } 
    var pixelAlpha = mousePixelOpacity(elem, x, y); 
    var track = Array; 
    for(var i = 0;i<50;i++){ 
    if($(elem).attr("id") == "game"){ return -1;} 
    if(pixelAlpha == 0 || $(elem).attr('class') != "tile"){ /////////HERE 
     track[i] = elem; 
     for(var z = 0; z<i+1; z++){ //hide elements 
     $(track[z]).hide(); 
     } 
     elem = document.elementFromPoint(x, y); //set the element right under the mouse. 
     pixelAlpha = mousePixelOpacity(elem, x, y); 
     for(var z = 0; z<i+1; z++){ //show all the recently hidden elements 
     $(track[z]).show(); 
     } 
    } 
    if($(elem).attr('class') == "tile" && pixelAlpha != 0){ ///// AND HERE 
     return elem; 
    } 
    } 
    return -1; 
} 

私は

getElement(x, y, "title");

//(This can be right) OR (both of these can be right.) 

if((pixelAlpha == 0) || (class="tile" && onlycountclassifIsaidsovar)){} 

のようなものを考えていたのようにマークされているものに変更

getElement(x, y, class)

ところで私はにいるよあなたがこの子犬を実際に見たいと思えば210。

ありがとうございます!

答えて

0

getTile()で3つの追加テストがあります。ブール型の3番目の引数(例えば、 'tile')を使うと、それらのテストを適用することができます。

+0

ありがとう、私はそれらをオンまたはオフに切り替えたくないので、トグルがオンであることを意味する文字列を入力してから、指定された文字列からクラスを選択します。 –

関連する問題