当前位置:网站首页>A case of gradually analyzing the splitting of classes -- colorful ball collisions
A case of gradually analyzing the splitting of classes -- colorful ball collisions
2022-07-29 03:10:00 【Brave * Niuniu】
Simple first step , Encapsulates a class, When called, the execution constructor is created as a small sphere ;

export default class {
Element;
constructor() {
this.Element = document.createElement('div');
Object.assign(this.Element.style, {
width: '50px',
height: '50px',
borderRadius: '50px',
backgroundColor:'red'
})
/* obtain div box , Add elements */
var div = document.querySelector('.div1')
div.appendChild(this.Element)
}
}
### Put the created ball on div in
appendTo(parent) {
if (typeof parent == "string") {
parent = document.querySelector(parent);
}
parent.appendChild(this.Element)
/* Get all the attributes of the parent element */
this.rect = parent.getBoundingClientRect();
}
Let him move again
move() {
if (this.x > this.rect.width - this.w || this.x < 0) this.speedX = -this.speedX
if (this.y> this.rect.height - this.h ||this.y<0) this.speedY =-this.speedY
this.x += this.speedX;
this.y += this.speedY;
this.Element.style.left = this.x + "px";
this.Element.style.top = this.y + "px";
}
static upData() {
for (var item of Circle.list) {
item.move();
}
}
Start putting cumbersome procedures on others js In file ;
Utils The file generates this random range number and random 16 Hexadecimal number
export default class {
static randomSpeed(speed, slowSpeed) {
var speed = Math.random() * (2 * speed) - speed;
return (speed>-slowSpeed && speed<slowSpeed) ?slowSpeed:speed
}
static randomColor() {
return Array(6).fill(1).reduce(function(v,t){
return v+(~~(Math.random()*16)).toString(16)},'#')
return Array(6).fill(1).reduce((v)=>v + (~~(Math.random() * 16)).toString(16) , '#')
}
}
边栏推荐
- C陷阱与缺陷 第3章 语义“陷阱” 3.7 求值顺序
- 融云 IM & RTC 能力上新盘点
- SAP 中国本地化内容汇总
- Shell编程规范与变量
- 04 | 后台登录:基于账号密码的登录方式(上)
- Analysis of concepts and terms in data warehouse
- mycat读写分离配置
- MySQL operation database data error: fatal error encoded during command execution
- Let's talk about the summary of single merchant function modules
- 【C】数组
猜你喜欢

融云实时社区解决方案
![[freeswitch development practice] unimrcp compilation and installation](/img/ef/b82326152326293bf98e89da28b887.png)
[freeswitch development practice] unimrcp compilation and installation

2022-07-28 第四小组 修身课 学习笔记(every day)

HTB-Blocky

Plato Farm在Elephant Swap上铸造的ePLATO是什么?为何具备高溢价?

HTB-Blue

Inventory of domestic and foreign project collaborative management software: SAAS and customization become a trend

单例模式(饿汉式 懒汉式)

【C】数组

Look at robot education and lead the mainstream of quality education
随机推荐
年内首个“三连跌” 95号汽油回归“8元时代“
Verilog的时间系统任务----$time、$stime、$realtime
VASP calculation task error: M_ divide:can not subdivide 8 nodes by 6
What is SOA (Service Oriented Architecture)?
融云 IM & RTC 能力上新盘点
西瓜书学习第六章---SVM
C traps and defects Chapter 3 semantic "traps" 3.2 pointers to non arrays
爆肝整理JVM十大模块知识点总结,不信你还不懂
算法---粉刷房子(Kotlin)
原理知识用得上
Unity 之游戏特效
The basic concept of the origin and connotation of maker Education
【打开新世界大门】看测试老鸟如何把API 测试玩弄在鼓掌之间
逐步分析类的拆分之案例——五彩斑斓的小球碰撞
MySQL installation and configuration super detailed tutorial and simple database and table building method
HTB-Blocky
多行文本省略
IDEA安装后无法启动
navicat新建数据库
[robot learning] matlab kinematics and ADMAS dynamics analysis of manipulator gripper