我正在创建一个小游戏,我在其中创建一个正方形表,第一个点击左下角的游戏就失败了。
我遇到了一个关于获取单击要删除的单元格的问题,我目前对它们淡出效果有效,但即使它们消失后它们仍然可以点击。
以下是让广场淡出的代码:
// 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 :(得分:0)
可能会删除功能单元格中的click事件侦听器,如下所示:
cellClick = function(cell){
cell.removeEventListener(“click”,onclick);
淡出(...) }