-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
85 lines (74 loc) · 1.98 KB
/
main.js
File metadata and controls
85 lines (74 loc) · 1.98 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
79
80
81
82
83
84
85
// Subtle particle background
(function () {
const canvas = document.getElementById('bg-canvas');
if (!canvas) return;
const ctx = canvas.getContext('2d');
let w, h, particles;
function resize() {
w = canvas.width = window.innerWidth;
h = canvas.height = window.innerHeight;
}
function init() {
resize();
const count = Math.floor((w * h) / 15000);
particles = Array.from({ length: Math.min(count, 80) }, () => ({
x: Math.random() * w,
y: Math.random() * h,
r: Math.random() * 1.5 + 0.5,
dx: (Math.random() - 0.5) * 0.3,
dy: (Math.random() - 0.5) * 0.3,
alpha: Math.random() * 0.3 + 0.05,
}));
}
function draw() {
ctx.clearRect(0, 0, w, h);
for (const p of particles) {
p.x += p.dx;
p.y += p.dy;
if (p.x < 0) p.x = w;
if (p.x > w) p.x = 0;
if (p.y < 0) p.y = h;
if (p.y > h) p.y = 0;
ctx.beginPath();
ctx.arc(p.x, p.y, p.r, 0, Math.PI * 2);
ctx.fillStyle = `rgba(232, 114, 12, ${p.alpha})`;
ctx.fill();
}
requestAnimationFrame(draw);
}
window.addEventListener('resize', () => {
resize();
});
init();
draw();
// Intersection Observer for fade-in on scroll
const observer = new IntersectionObserver(
(entries) => {
entries.forEach((entry) => {
if (entry.isIntersecting) {
entry.target.style.animationPlayState = 'running';
}
});
},
{ threshold: 0.1 }
);
document.querySelectorAll('section > *').forEach((el) => {
observer.observe(el);
});
// Smooth nav background on scroll
const nav = document.getElementById('nav');
let ticking = false;
window.addEventListener('scroll', () => {
if (!ticking) {
requestAnimationFrame(() => {
if (window.scrollY > 50) {
nav.style.borderBottomColor = '#e8720c22';
} else {
nav.style.borderBottomColor = '#222';
}
ticking = false;
});
ticking = true;
}
});
})();