当前位置:网站首页>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) , '#')
}
}
边栏推荐
- 年内首个“三连跌” 95号汽油回归“8元时代“
- C陷阱与缺陷 第3章 语义“陷阱” 3.7 求值顺序
- 从零开始实现lmax-Disruptor队列(六)Disruptor 解决伪共享、消费者优雅停止实现原理解析
- [NPM error] - NPM err code eresolve and NPM err eresolve could not resolve problems
- 生产部署zabbix5.0笔记
- Flask creation process day05-06 creation project
- 第09章_性能分析工具的使用
- 数据截断及估计
- Linux下安装MySQL8.0的详细步骤
- [open the door to the new world] see how the old bird of testing plays API testing between applause
猜你喜欢

navicat新建数据库

Redis配置缓存过期监听事件触发

Weekly recommended short videos: how to make product development more effective?

C语言基础知识点汇总

西瓜书学习第六章---SVM

数字图像处理 第10章——图像分割

2.nodejs--路径(_dirname,_filname)、url网址、querystring模块、mime模块、各种路径(相对路径)、网页的加载(面试题*)

Analysis of concepts and terms in data warehouse

逐步分析类的拆分之案例——五彩斑斓的小球碰撞

Chapter 09_ Use of performance analysis tools
随机推荐
Interpreting AI robots' pet raising and leading fashion trends
VIM common commands
C traps and defects Chapter 3 semantic "traps" 3.3 array declaration as parameters
接口自动化测试实践指导(上):接口自动化需要做哪些准备工作
TP5.0 小程序用户无需登录,直接获取用户手机号。
MYSQL入门与进阶(十一)
明明开发薪资高,为什么我还是选了测试?
Analysis of Project-based Learning Creativity in steam Education
MySQL installation and configuration super detailed tutorial and simple database and table building method
C陷阱与缺陷 第3章 语义“陷阱” 3.1 指针与数组
[robot learning] matlab kinematics and ADMAS dynamics analysis of manipulator gripper
Tp5.0 applet users do not need to log in and directly obtain the user's mobile number.
MySQL - the difference between count (field), count (primary key), count (1), count (*)
Alibaba Sentinel - 工作流程及原理解析
"PHP Basics" output approximate value of PI
Unable to start after idea installation
「PHP基础知识」输出圆周率的近似值
2022-07-28 顾宇佳 学习笔记
MySQL忘记密码怎么办
C traps and defects Chapter 3 semantic "traps" 3.8 operators &, |, and!