2016-04-29 12 views
0

私は四角いテーブルを作成する小さなゲームを作成しています。最初のものは左下の部分をクリックすると消えます。セル消去の問題

クリックして消去するセルを取得する際に問題がありますが、現在はフェードアウトする効果がありますが、消えてもクリック可能なままです。ここで

はフェードする四角形を取得するための私のコードです:

// Fade an element down a little further. 
    fadeOut = function fadeOut(state) { 
     // Make fadeOut unavailable until the whole fade-out is finished. 
     fadeOut.isAvailableToRun = false; 
     // Update the distance moved and apply it to the element. (decrement to move down?) 
     state.distance += state.distanceIncrement; 
     state.element.style.top = state.distance + 'px'; //move up by pixels 
     // Update the opacity and apply it to the element. 
     state.opacity += state.opacityIncrement; 
     state.element.style.opacity = state.opacity; 
     //if opacity is > 0 , fade it out into the ethers 
     if (state.opacity > 0) { 
      // If the element is still showing, wait a bit and then continue fading it. 
     setTimeout(function() { 
      fadeOut(state); 
     }, state.timeIncrement); 
     } 
    }; 

//contains values to use for fadeOut 
    cellClick = function (cell) { 
     fadeOut({ 
     distance: 0, // initial distance from start 
     distanceIncrement: 1, // number of pixels to move each timer tick 
     element: cell, // element to move and fade (cell, element passed as a parameter to the click cell function) 
     opacity: 1, // initial opacity 
     opacityIncrement: -0.01, // how much to fade each timer tick 
     pause: 1000, // milliseconds to pause after completed fade 
     timeIncrement: 10 // milliseconds for each timer tick 
     }); 
    }; 

は、どのように私はそれぞれの正方形が退色後に削除するために得ることができますか?

Hereは完全に自分のコードです。

答えて

0

おそらく以下のようなあなたの関数cellClickにclickイベントリスナーを削除します。

cellClick =機能(セル){

cell.removeEventListener(onclickの、 "クリック")。

fadeOut(...)

+0

ありがとうございました!私は 'removeEventListener'が存在していたことに気付かず、まだかなり新しい。それでも問題を起こすことはありますが、私はそれを理解することができます。将来何かをする人のために – user3335607

+0

、cell.onclick = nullを使用して修正しました – user3335607

+0

これはそれを削除する巧妙な方法でした。 –