-
Notifications
You must be signed in to change notification settings - Fork 118
/
bubble.js
52 lines (41 loc) · 1.82 KB
/
bubble.js
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
document.addEventListener("DOMContentLoaded", function () {
let bubblesEnabled = false;
const bubbleToggleButton = document.getElementById("bubble-toggle-button");
bubbleToggleButton.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" width="30" height="30" viewBox="0 0 24 24" fill="none">
<circle cx="12" cy="12" r="10" fill="lightblue" opacity="10"/>
<circle cx="8" cy="8" r="4" fill="white" opacity="10"/>
</svg>`;
function createBubble() {
if (!bubblesEnabled) return;
const bubble = document.createElement('div');
bubble.className = 'bubble';
bubble.style.left = `${Math.random() * 100}vw`;
bubble.style.top = `${window.scrollY + Math.random() * window.innerHeight}px`;
const size = Math.random() * 40 + 10;
bubble.style.width = `${size}px`;
bubble.style.height = `${size}px`;
document.body.appendChild(bubble);
setTimeout(() => {
bubble.remove();
}, 4000);
}
let bubbleInterval = setInterval(createBubble, 300);
window.addEventListener('scroll', () => {
if (bubblesEnabled) {
createBubble();
}
});
bubbleToggleButton.addEventListener("click", function () {
bubblesEnabled = !bubblesEnabled;
if (bubblesEnabled) {
bubbleInterval = setInterval(createBubble, 300);
this.innerHTML = '<span style="font-size: 23px;border: none; margin: 0; padding: 0px">🚫</span>';
} else {
clearInterval(bubbleInterval);
this.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg" width="30" height="30" viewBox="0 0 24 24" fill="none">
<circle cx="12" cy="12" r="10" fill="lightblue" opacity="10"/>
<circle cx="8" cy="8" r="4" fill="white" opacity="10"/>
</svg>`;
}
});
});