2016-04-29 138 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象下面這樣:

cellClick =功能(電池){

cell.removeEventListener( 「點擊」,的onclick);

fadeOut(...) }

+0

謝謝!我沒有意識到我'removeEventListener'存在,仍然非常新。仍然有問題得到它的工作,但我應該能夠弄清楚。 – user3335607

+0

任何人在將來做某事,我用cell.onclick = null來修復它 – user3335607

+0

這是一個聰明的方法來刪除它。 –