当前位置:网站首页>Starting from scratch (IV) enemy aircraft flying out of the border disappear automatically
Starting from scratch (IV) enemy aircraft flying out of the border disappear automatically
2022-06-11 06:46:00 【Dare you look at the avatar for three seconds?】
Problems encountered

As shown in the figure , In order to realize the random increase of enemy aircraft and the first random flight of players on the stage, do you know , When checking the console, I found , When the enemy plane flies over the stage, it will not disappear automatically , So that the program will take up too much memory space , The situation is somewhat similar to the memory leak that is not released in time when dynamic memory allocation is implemented , So when the computer slows down at visible speed , How to make the enemy aircraft disappear automatically becomes more and more difficult
Before that, first understand a few concepts
Every enemy plane is loaded by us html One of the nodes in , Or labels
understand dom node
document object model---- Document object model
Our need is , After the enemy aircraft flies over the stage, the corresponding... Will be deleted automatically html node , Before deleting, we need to find a way to get the corresponding node of the aircraft flying out of the stage
dom The attribute acquisition problem of the node
Get the properties of all nodes ( Height or something ) Not directly in js Inside point , You can't get , This also applies jq Why
But the input field can be clicked directly value
Specific code :
// When you leave the stage, remember to remove dom node
setInterval(function(){
for(i=0;i<enemy.length;i++){
var tmp_enemy=parseFloat($(enemy[i]).css("top"));
var tmp_stage=$(stage).height();
// console.log(tmp_enemy);
// console.log(typeof($(tmp_stage).height()));
if(tmp_enemy>tmp_stage){
$(enemy[i]).remove();
console.log(" Removed successfully ")
}
}
},500)
边栏推荐
- Throttling and anti shake
- Docker installation of MySQL and redis
- 你知道IT人才外派服务报价是怎样的么?建议程序员也了解下
- FPGA interview topic notes (I) - FPGA development process, metastable state and competitive risk, build and hold time, asynchronous FIFO depth, etc
- Sentinel annotation support - @sentinelresource usage details
- PHP laravel8 send email
- Analyze the principle of configuration center from the perspective of Nacos client
- Teach everyone how to implement an electronic signature
- Resolve typeerror: ctx injections. tableRoot.$ scopedSlots[ctx.props.column.slot] is not a function
- Redux learning (III) -- using Redux saga, writing middleware functions, and splitting reducer files
猜你喜欢

MongoDB安装

网狐游戏服务器房间配置约战定制功能实现

538.把二叉搜索树转换成累加树

jenkins-不同风格的项目构建

Won't virtual DOM be available in 2022? Introduction to virtual Dom and complete implementation of diff and patch

Detailed explanation of mutual call between C language and Lua

Learn C language well from keywords

Mongodb installation

572. 另一个树的子树

572. subtree of another tree
随机推荐
双周投融报:资本抢滩元宇宙游戏
fatal: refusing to merge unrelated histories
JS judge whether the year is a leap year and the number of days in the month
SQL语言-查询语句
About the principle and code implementation of Siou (review IOU, giou, Diou, CIO)
QT script document translation (I)
JS two methods to determine whether there are duplicate values in the array
通过两种方式手写一个消息队列
break,continue有什么区别和用法?
不同VLAN间的通信
3.1 测试函数的命名规则
Sentinel annotation support - @sentinelresource usage details
Learn C language well from keywords
022-Redis数据库0基础入门
572. subtree of another tree
关于组织开展2022年宁波市重点首版次软件申报工作的通知
Teach everyone how to implement an electronic signature
解决ffmpeg獲取AAC音頻文件duration不准
What is sentinel produced by Ali?
235-二叉搜索树的最近公共祖先