-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbubble.html
More file actions
76 lines (72 loc) · 2.16 KB
/
bubble.html
File metadata and controls
76 lines (72 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta http-equiv="Pragma" content="no-cache, no-store, must-revalidate, max-age=0">
<meta http-equiv="Cache-Control" content="no-cache, no-store, must-revalidate, max-age=0">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<meta name="format-detection" content="telephone=no">
<title>Andself</title>
<style>
.paopao {
position: absolute;
pointer-events: none;
width: 24px;
height: 24px;
border-radius: 100%;
animation: fade 0.8s;
}
@keyframes fade {
from {
opacity: 1;
} to {
opacity: 0;
transform: translateY(-80px) scale(1.5);
}
}
</style>
</head>
<body>
<div id="app">
<select name="mode" value="click" id="listerMode">
<option value="click">click</option>
<option value="mousemove">mousemove</option>
<option value="mousedown">mousedown</option>
</select>
</div>
<script>
class Bubble {
constructor (mode = 'click') {
this.mode = mode
}
static getRandomColor () {
return '#' + (Math.random() * (0xffffff + 1) << 0).toString(16)
}
createBubble (event) {
const { clientX, clientY } = event
const dom = document.createElement('div')
dom.className = 'paopao'
dom.style.left = clientX + 'px'
dom.style.top = clientY + 'px'
dom.style.backgroundColor = Bubble.getRandomColor()
document.body.appendChild(dom)
dom.addEventListener('animationend', () => { document.body.removeChild(dom) })
}
init () {
document.addEventListener(this.mode, this.createBubble, false)
}
changeMode (newMode) {
document.removeEventListener(this.mode, this.createBubble, false)
this.mode = newMode
document.addEventListener(newMode, this.createBubble, false)
}
}
const myBubble = new Bubble()
myBubble.init()
document.getElementById('listerMode').onchange = function (event) {
myBubble.changeMode(event.target.value)
}
</script>
</body>
</html>