Skip to content

Commit bf1747e

Browse files
committed
feat: pointer-event HTML example
1 parent 38f3b30 commit bf1747e

File tree

1 file changed

+98
-0
lines changed

1 file changed

+98
-0
lines changed

css/pointer-event.html

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Pointer Event</title>
7+
<style>
8+
body {
9+
margin: 0;
10+
}
11+
#pointer-event-container {
12+
width: 100vw;
13+
height: 100vh;
14+
}
15+
.circle {
16+
width: 30px;
17+
height: 30px;
18+
border-radius: 50%;
19+
position: absolute;
20+
transform: translate(-50%, -50%);
21+
display: flex;
22+
justify-content: center;
23+
align-items: center;
24+
background-color: #aaa;
25+
box-shadow: 0 0 5px 10px #aaa;
26+
color: #fff;
27+
animation: fadeOut 1s 0.1s ease-in-out forwards;
28+
}
29+
@keyframes fadeOut {
30+
from {
31+
opacity: 1;
32+
}
33+
99% {
34+
opacity: 0;
35+
scale: 1.5;
36+
}
37+
to {
38+
opacity: 0;
39+
display: none;
40+
}
41+
}
42+
#pointer-type-container {
43+
text-align: center;
44+
padding: 10%;
45+
font-size: 20px;
46+
border: 1px solid #000;
47+
}
48+
#pointer-type {
49+
display: inline-block;
50+
min-width: 100px;
51+
font-weight: bold;
52+
}
53+
</style>
54+
</head>
55+
<body>
56+
<div id="pointer-event-container">
57+
<p id="pointer-type-container">
58+
pointer type:
59+
<span id="pointer-type"></span>
60+
</p>
61+
</div>
62+
<script>
63+
const container = document.getElementById('pointer-event-container');
64+
const box = document.getElementById('pointer-type');
65+
66+
const appendCircle = (event) => {
67+
const circle = document.createElement('div');
68+
circle.classList.add('circle');
69+
circle.style.left = event.clientX + 'px';
70+
circle.style.top = event.clientY + 'px';
71+
circle.innerText = event.pointerId;
72+
73+
container.appendChild(circle);
74+
circle.setPointerCapture(event.pointerId);
75+
}
76+
77+
container.addEventListener('pointerdown', (event) => {
78+
console.log(event.target);
79+
if(event.target.classList.contains('circle')) {
80+
return;
81+
}
82+
83+
appendCircle(event);
84+
85+
box.innerText = event.pointerType;
86+
});
87+
88+
container.addEventListener('pointerup', (event) => {
89+
setTimeout(() => {
90+
box.innerText = '';
91+
}, 500);
92+
});
93+
</script>
94+
</body>
95+
</html>
96+
97+
98+

0 commit comments

Comments
 (0)