我正在開發一個小遊戲,在這個遊戲中我需要每隔一段時間纔會發生一場災難。 此次災難必須動搖我的MainFrame元素&從類別.House,從構建數組和DOM中移除所有元素。設置jQuery刪除方法作爲動畫完成回調不起作用
此代碼在某種程度上起作用,問題在於它不會從DOM中刪除元素,只能從數組中刪除元素。 你能幫我搞定它嗎? 我第一次使用這個網站,所以我希望我沒有留下任何相關的東西。
setInterval(function() {
var iDisasterChance = getRandomNumber(1, 12);
if (iDisasterChance === 1)
{
$(".MainFrame").effect("shake", {times: 8}, 4000);
//$(".House").effect("explode", {pieces: 24}, 4000);
$(".House").effect("explode", {pieces: 24}, 4000, $(".House").remove); // TODO: bug - leaves elements in the dom
//$(".House").remove();
oCity.aBuildings.length = 0;
console.log(iDisasterChance +' of 12');
console.log('*** DISASTER ! AVOIDED ***');
console.dir(oCity.aBuildings);
return false;
}
else
{
console.log(iDisasterChance +' of 12');
console.log('*** DISASTER AVOIDED ***');
}
}, 10000);
作爲一個建議,請記住,您可以使用您的瀏覽器的控制檯(或者,優先考慮Firebug或類似的)添加**斷點**並逐步檢查代碼(即,line_line),以查看斷點。在這種線性代碼中特別「有用」。記得在開始的時候把它放在正確的位置,在這種情況下'var isDisasterChance = ...'! – Nico