-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathscript.js
More file actions
56 lines (49 loc) · 1.83 KB
/
script.js
File metadata and controls
56 lines (49 loc) · 1.83 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
// Init AOS
document.addEventListener("DOMContentLoaded", function() {
AOS.init({ once: true, offset: 50, duration: 800 });
initTheme();
});
function initTheme() {
const toggleBtn = document.getElementById('theme-toggle');
const html = document.documentElement;
// Check Storage or System Preference
const savedTheme = localStorage.getItem('theme');
const sysTheme = window.matchMedia('(prefers-color-scheme: light)').matches ? 'light' : 'dark';
const currentTheme = savedTheme || sysTheme;
html.setAttribute('data-theme', currentTheme);
updateParticles(currentTheme);
// Toggle Event
toggleBtn.addEventListener('click', () => {
const theme = html.getAttribute('data-theme');
const newTheme = theme === 'dark' ? 'light' : 'dark';
html.setAttribute('data-theme', newTheme);
localStorage.setItem('theme', newTheme);
updateParticles(newTheme);
});
}
function updateParticles(theme) {
const color = theme === 'dark' ? '#00f2ff' : '#4f46e5';
const opacity = theme === 'dark' ? 0.4 : 0.6;
particlesJS("particles-js", {
"particles": {
"number": { "value": 60, "density": { "enable": true, "value_area": 800 } },
"color": { "value": color },
"shape": { "type": "circle" },
"opacity": { "value": opacity, "random": true },
"size": { "value": 3, "random": true },
"line_linked": {
"enable": true, "distance": 150, "color": color, "opacity": 0.2, "width": 1
},
"move": { "enable": true, "speed": 2, "direction": "none", "out_mode": "out" }
},
"interactivity": {
"detect_on": "canvas",
"events": {
"onhover": { "enable": true, "mode": "repulse" },
"onclick": { "enable": true, "mode": "push" }
},
"modes": { "repulse": { "distance": 100 }, "push": { "particles_nb": 4 } }
},
"retina_detect": true
});
}