Add parent checking before inserting or removing the child

This commit is contained in:
Phillweston
2024-05-15 12:46:17 +00:00
parent 8c5d31498b
commit a66c416fa4
12 changed files with 34 additions and 15 deletions

View File

@@ -3,7 +3,7 @@ const idFlutteringRibbon = 'canvasFlutteringRibbon'
function destroyFlutteringRibbon() {
const ribbon = document.getElementById(idFlutteringRibbon)
if (ribbon && ribbon.parentNode) {
if (ribbon && ribbon.parentNode && ribbon.parentNode.contains(ribbon)) {
ribbon.parentNode.removeChild(ribbon)
}
}

View File

@@ -109,7 +109,7 @@ function createNest() {
function destroyNest() {
const nest = document.getElementById(idNest)
if(nest && nest.parentNode){
if (nest && nest.parentNode && nest.parentNode.contains(nest)) {
nest.parentNode.removeChild(nest)
}
}

View File

@@ -80,7 +80,7 @@ function createRibbon() {
function destroyRibbon() {
const ribbon = document.getElementById(idRibbon)
if (ribbon && ribbon.parentNode) {
if (ribbon && ribbon.parentNode && ribbon.parentNode.contains(ribbon)) {
ribbon.parentNode.removeChild(ribbon)
}
}

View File

@@ -165,9 +165,11 @@ function createSakura() {
function stopp() {
if (staticx) {
var child = document.getElementById(id)
child.parentNode.removeChild(child)
window.cancelAnimationFrame(stop)
staticx = false
if (child && child.parentNode && child.parentNode.contains(child)) {
child.parentNode.removeChild(child)
window.cancelAnimationFrame(stop)
staticx = false
}
} else {
startSakura()
}
@@ -177,7 +179,7 @@ function createSakura() {
// 销毁樱花雨
function destroySakura() {
const sakura = document.getElementById(idSakura)
if (sakura && sakura.parentNode) {
if (sakura && sakura.parentNode && sakura.parentNode.contains(sakura)) {
sakura.parentNode.removeChild(sakura)
}
}