Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
78 lines (64 loc) · 2.16 KB
/
Copy pathscript.js
File metadata and controls
78 lines (64 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
77
78
var container = document.getElementById("container");
var rainContainer = document.getElementById("rainContainer");
var dropsContainer1 = document.getElementById("drops1");
var dropsContainer2 = document.getElementById("drops2");
var documentHeight = document.documentElement.style.setProperty('--document-height', `${document.documentElement.scrollHeight}px`);
if (/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)) {
dropsAmount = 20;
existingDrops = container.querySelectorAll(".drop");
existingDrops.forEach(drop => {
drop.style.width = "2px";
drop.style.height = "10px";
});
} else{
dropsAmount = 60;
}
function currentWSize(){
WSize = window.innerWidth;
return WSize;
}
function removeRain(){
existingDrops = container.querySelectorAll(".drop");
existingDrops.forEach(drop => drop.remove());
}
function makeRain(){
removeRain();
for (i=0;i<dropsAmount;i++){
drop = document.createElement("div");
drop.className = "drop";
drop.style.opacity = 0.7;
drop.style.left = Math.random() * currentWSize() + "px"
drop.style.animationDelay = (Math.random()*2) + "s"
dropsContainer1.appendChild(drop);
if (i>dropsAmount/2){
dropsContainer2.appendChild(drop);
}
}
}
function fadeRain(){
existingDrops = container.querySelectorAll(".drop");
existingDrops.forEach(drop => {
drop.style.opacity = 0;
});
}
window.addEventListener("load", makeRain);
prevSize = currentWSize();
window.addEventListener("resize", () => {
if (prevSize != currentWSize()){
fadeRain();
setTimeout(makeRain,500);
}
prevSize = currentWSize();
});
window.addEventListener("beforeunload", makeRain);
disableRainBtn = document.getElementById("disableRainBtn");
disableRainBtn.addEventListener("click", () => {
if (disableRainBtn.classList.contains("rainEnabled")){
rainContainer.style.display = "none";
disableRainBtn.classList.remove("rainEnabled");
}
else {
rainContainer.style.display = "block";
disableRainBtn.classList.add("rainEnabled");
}
})