-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
110 lines (91 loc) · 3.14 KB
/
main.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
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
//home page
const open = document.getElementById('open')
const close = document.getElementById('close')
const container = document.querySelector('.container')
open.addEventListener('click', () => container.classList.add('show-nav'))
close.addEventListener('click', () => container.classList.remove('show-nav'))
// path: themes
const toggle = document.querySelector('.toggle')
toggle.addEventListener('click', (e) => {
const html = document.querySelector('html')
if (html.classList.contains('dark')) {
html.classList.remove('dark')
e.target.innerHTML = 'Dark mode'
} else {
html.classList.add('dark')
e.target.innerHTML = 'Light mode'
}
})
//button let's play
const openBtn = document.getElementById("open");
const playBtn = document.getElementById("playButton");
playBtn.addEventListener("click", () => {
openBtn.click();
});
const closeBtn = document.getElementById("close");
const circleContainer = document.querySelector(".circle-container");
openBtn.addEventListener("click", () => {
circleContainer.classList.add("show-nav");
});
closeBtn.addEventListener("click", () => {
circleContainer.classList.remove("show-nav");
});
//screen loading
const loadText = document.querySelector('.loading-text')
const bg = document.querySelector('.bg')
let load = 0
let int = setInterval(blurring, 30)
function blurring() {
load++
if (load > 99) {
clearInterval(int)
}
loadText.innerText = `${load}%`
loadText.style.opacity = scale(load, 0, 100, 1, 0)
bg.style.filter = `blur(${scale(load, 0, 100, 30, 0)}px)`
}
const scale = (num, in_min, in_max, out_min, out_max) => {
return ((num - in_min) * (out_max - out_min)) / (in_max - in_min) + out_min
}
// crazy title
document.addEventListener("DOMContentLoaded", function () {
const title = document.querySelector(".crazy-title");
title.innerHTML = title.textContent
.split("")
.map((char, i) => `<span style="animation-delay:${i * 0.1}s">${char}</span>`)
.join("");
//somke effect
const canvas = document.getElementById("smokeCanvas");
const ctx = canvas.getContext("2d");
canvas.width = window.innerWidth;
canvas.height = window.innerHeight;
const particles = [];
function createParticle() {
return {
x: window.innerWidth / 2,
y: window.innerHeight / 2 - 100,
size: Math.random() * 20 + 5,
speedX: Math.random() * 2 - 1,
speedY: Math.random() * -3 - 1,
opacity: 1
};
}
function animateParticles() {
ctx.clearRect(0, 0, canvas.width, canvas.height);
particles.push(createParticle());
for (let i = 0; i < particles.length; i++) {
const p = particles[i];
p.x += p.speedX;
p.y += p.speedY;
p.opacity -= 0.02;
ctx.globalAlpha = p.opacity;
ctx.fillStyle = "#fff";
ctx.beginPath();
ctx.arc(p.x, p.y, p.size, 0, Math.PI * 2);
ctx.fill();
}
particles.filter(p => p.opacity > 0);
requestAnimationFrame(animateParticles);
}
animateParticles();
});