-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
107 lines (91 loc) · 2.77 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>VS | 👍 </title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div class="thumbsup-background">
<!-- Emojis in the background -->
</div>
<div class="switch" onclick="toggleLike()">
<div class="thumbsup">👍</div>
</div>
<script>
let liked = false;
let emojiBackground = null;
function toggleLike() {
const likeSwitch = document.querySelector('.switch');
likeSwitch.classList.toggle('thumbeduped');
liked = !liked;
if (liked) {
createLikeEmojis();
} else {
removeLikeEmojis();
}
}
function createLikeEmojis() {
const likeBackground = document.createElement('div');
likeBackground.classList.add('thumbsup-background');
document.body.appendChild(likeBackground);
setTimeout(() => {
likeBackground.classList.add('show');
}, 10);
const emojiSize = 40;
const padding = 20;
const emojiCount = 160;
const maxAttempts = 100;
for (let i = 0; i < emojiCount; i++) {
let left, top;
let attempts = 0;
do {
left = Math.random() * (window.innerWidth - emojiSize - padding);
top = Math.random() * (window.innerHeight - emojiSize - padding);
let collision = false;
for (const existingEmoji of likeBackground.children) {
const rect1 = {
left,
top,
right: left + emojiSize,
bottom: top + emojiSize,
};
const rect2 = existingEmoji.getBoundingClientRect();
if (
rect1.left < rect2.right &&
rect1.right > rect2.left &&
rect1.top < rect2.bottom &&
rect1.bottom > rect2.top
) {
collision = true;
break;
}
}
attempts++;
if (!collision) break;
} while (attempts < maxAttempts);
if (attempts < maxAttempts) {
const likeEmoji = document.createElement('div');
likeEmoji.classList.add('thumbsup-emoji');
likeEmoji.innerText = '👍';
likeEmoji.style.left = `${left}px`;
likeEmoji.style.top = `${top}px`;
likeBackground.appendChild(likeEmoji);
} else {
break;
}
}
emojiBackground = likeBackground;
}
function removeLikeEmojis() {
if (emojiBackground) {
emojiBackground.classList.remove('show');
setTimeout(() => {
emojiBackground.remove();
emojiBackground = null;
}, 500);
}
}
</script>
</body>
</html>