javascript - Proper deleting HTML DOM nodes -
i'm trying create star shining animation.
function showstars() { //if ($('img.star').length > 5) // return; var x = math.floor(math.random() * gameareawidth) - 70; var y = math.floor(math.random() * gameareaheight); var star = document.createelement("img"); star.setattribute("class", "star"); star.setattribute("src", imagespath + "star" + getrandom(1, 3) + ".png"); star.style.left = x + "px"; star.style.top = y + "px"; gamearea.appendchild(star); // light. settimeout(function () { star.setattribute("class", "star shown"); }, 0); // put out. settimeout(function () { star.setattribute("class", "star"); }, 2000); // delete. settimeout(function () { gamearea.removechild(star); }, 4000); settimeout(function () { showstars(); }, 500); }
it works fine until uncomment following code supposed regulate star count:
//if ($('img.star').length > 5) // return;
then stops work if created stars not removed (the first 5 stars blink nothing happens). why jquery selector select them after gamearea.removechild(star);
? isn't enough remove them parent node?
browser: google chrome 17.
regards,
change commented out lines
if ($('img.star').length > 5) { settimeout(function () { showstars(); }, 500); return; }
to keep showstars recursion going.
Comments
Post a Comment