2016-04-29 71 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

这是一个聪明的方法来删除它。 –