JavaScript中销毁img标签 (子弹飞出界面后销毁)

this.isDestroy=function () {//销毁条件 飞出界面后销毁
    if(bulletY<-height){
        return true;
    }
    else{
        return false;
    }
};
var bulletId;
this.isimgDestroy=function () {//销毁条件 飞出界面后销毁
    if(this.isDestroy()){
        bulletId=document.getElementById('bullet');
        bulletId.outerHTML='';
    }
};
不同的js函数中
this.run=function () {
    bullets.forEach(function (bullet) {
        bullet.run();
        if(bullet.isDestroy()){
            //销毁子弹数组里面的子弹
            bullets.splice(bullet,1);
            //把子弹里面的图片元素销毁
            bullet.isimgDestroy();
        }
    })
};

猜你喜欢

转载自blog.csdn.net/junling_xhu/article/details/80895188