鼠标点击后,实现烟花效果
当鼠标点击后,会有一个小点慢慢上升,上升到鼠标点击的高度后,就会炸开
点击两个试试
html代码
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
*{
margin: 0;
padding: 0;
}
.box{
width: 800px;
height: 600px;
background-color:#333;
margin:100px auto;
position:relative;
}
.fire{
width: 20px;
height: 20px;
background-color:hotpink;
position:absolute;
left: 0;
}
</style>
</head>
<body>
<div class="box">
</div>
<script>
// 点击事件 => box
// 创建 fire
// + 位置 left 和 光标一致
// + bottom 0
// fire 运动 从 bottom 0 的位置 跑到 光标点击的位置
// 移除
// 随机创建火花
// 设置每一个 火花的坐标 和 光标保持一致
// 炸开
</script>
<script src="./utiles.js"></script>
<script src="./index.js"></script>
<script>
const box = document.querySelector('.box')
new Fireworks(box)
</script>
</body>
</html>
index.js
class Fireworks{
constructor(ele){
this.ele = ele || document.querySelector('.box')
this.init()
}
init