擦除单元格问题
Erasing cells issue
我正在创建一个小游戏,其中我创建了 table 个方块,第一个点击左下角方块的人输了。
我在获取单击以擦除的单元格时遇到问题,我目前有一个让它们淡出的效果,但即使它们消失后它们仍然可以点击。
这是让方块褪色的代码:
// 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 是我的完整代码。
可能会删除您的函数 cellClick 中的点击事件侦听器,如下所示:
cellClick = 函数(单元格){
cell.removeEventListener("click", onclick);
淡出(...)
}
我正在创建一个小游戏,其中我创建了 table 个方块,第一个点击左下角方块的人输了。
我在获取单击以擦除的单元格时遇到问题,我目前有一个让它们淡出的效果,但即使它们消失后它们仍然可以点击。
这是让方块褪色的代码:
// 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 是我的完整代码。
可能会删除您的函数 cellClick 中的点击事件侦听器,如下所示:
cellClick = 函数(单元格){
cell.removeEventListener("click", onclick);
淡出(...) }