Once animated images are off the screen, how do I delete them?

时间:2019-04-17 00:54:13

标签: javascript html

So, I want to make a cookie clicker type game and when the screen is clicked, I want to have an animated image fall from the top and off of the screen. I'm pretty sure the images would build up even though I can't see them. There must be a way to delete them once they are off of the screen. Would it be an if statement? Like, once it reaches a certain dimension, remove the image? Help me please. :D

1 个答案:

答案 0 :(得分:0)

您可以运行独立的作业,而不是在代码中放置一个“ if”条件,使动画图像从屏幕的顶部和顶部掉落,您可以根据该条件选择要删除的DOM元素/图像(隐藏的图片)。

setInterval(function(){
    //code to select the relevant images based on css class/ other conditions 
    //like position on page etc and then remove them.
    $('img.hidden').remove();
},1000);