-
Notifications
You must be signed in to change notification settings - Fork 0
/
glowing-boll-7.html
153 lines (142 loc) · 3.68 KB
/
glowing-boll-7.html
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Pulsing Glowing Pattern Lock</title>
<style>
* {
margin: 0;
padding: 0;
box-sizing: border-box;
}
body {
display: flex;
justify-content: center;
align-items: center;
height: 100vh;
background-color: #2c3e50;
font-family: Arial, sans-serif;
}
.pattern-lock-container {
position: relative;
}
.pattern-lock {
display: grid;
grid-template-columns: repeat(3, 1fr);
grid-gap: 20px;
width: 240px;
height: 240px;
}
.circle {
width: 60px;
height: 60px;
border-radius: 50%;
background: #34495e;
position: relative;
cursor: pointer;
transition: box-shadow 0.3s, transform 0.3s;
}
.circle.active {
box-shadow: 0 0 20px 10px #16a085, inset 0 0 20px #16a085;
transform: scale(1.3);
}
svg {
position: absolute;
top: 0;
left: 0;
width: 240px;
height: 240px;
pointer-events: none;
}
line {
stroke: #16a085;
stroke-width: 6;
stroke-linecap: round;
}
</style>
</head>
<body>
<div class="pattern-lock-container">
<svg></svg>
<div class="pattern-lock">
<div class="circle" data-id="1"></div>
<div class="circle" data-id="2"></div>
<div class="circle" data-id="3"></div>
<div class="circle" data-id="4"></div>
<div class="circle" data-id="5"></div>
<div class="circle" data-id="6"></div>
<div class="circle" data-id="7"></div>
<div class="circle" data-id="8"></div>
<div class="circle" data-id="9"></div>
</div>
</div>
<script>
const circles = document.querySelectorAll('.circle');
const svg = document.querySelector('svg');
let isMouseDown = false;
let pattern = [];
let prevCircle = null;
const createLine = (start, end) => {
const line = document.createElementNS('http://www.w3.org/2000/svg', 'line');
line.setAttribute('x1', start.x);
line.setAttribute('y1', start.y);
line.setAttribute('x2', end.x);
line.setAttribute('y2', end.y);
svg.appendChild(line);
};
const startPattern = (circle) => {
if (!pattern.includes(circle.dataset.id)) {
pattern.push(circle.dataset.id);
circle.classList.add('active');
const rect = circle.getBoundingClientRect();
const pos = { x: rect.left rect.width / 2, y: rect.top rect.height / 2 };
if (prevCircle) createLine(prevCircle, pos);
prevCircle = pos;
}
};
circles.forEach(circle => {
circle.addEventListener('mousedown', () => {
isMouseDown = true;
startPattern(circle);
});
circle.addEventListener('mouseenter', () => {
if (isMouseDown) startPattern(circle);
});
circle.addEventListener('touchstart', (e) => {
e.preventDefault();
startPattern(circle);
});
circle.addEventListener('touchmove', (e) => {
const touch = e.touches[0];
const element = document.elementFromPoint(touch.clientX, touch.clientY);
if (element && element.classList.contains('circle') && isMouseDown) {
startPattern(element);
}
});
});
const resetPattern = () => {
pattern = [];
prevCircle = null;
circles.forEach(circle => circle.classList.remove('active'));
while (svg.firstChild) {
svg.removeChild(svg.firstChild);
}
};
document.addEventListener('mouseup', () => {
if (isMouseDown) {
isMouseDown = false;
alert('Pattern: ' pattern.join('-'));
resetPattern();
}
});
document.addEventListener('touchend', () => {
if (isMouseDown) {
isMouseDown = false;
alert('Pattern: ' pattern.join('-'));
resetPattern();
}
});
</script>
</body>
</html>