-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
93 lines (77 loc) · 2.66 KB
/
script.js
File metadata and controls
93 lines (77 loc) · 2.66 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
86
87
88
89
90
91
92
93
// Create star field background when document is fully loaded
document.addEventListener("DOMContentLoaded", function () {
const starField = document.getElementById("star-field");
const header = document.querySelector("header");
// Create stars for the global background
createStars(starField, 300);
// Create extra dense stars specifically for the header
createDenseStarsInHeader(header, 200);
// Add scroll animation for sections
const sections = document.querySelectorAll("section");
window.addEventListener("scroll", () => {
const scrollY = window.scrollY;
sections.forEach((section) => {
const sectionTop = section.offsetTop;
const sectionHeight = section.offsetHeight;
if (
scrollY > sectionTop - window.innerHeight / 1.5 &&
scrollY < sectionTop + sectionHeight
) {
section.style.opacity = "1";
section.style.transform = "translateY(0)";
} else {
section.style.opacity = "0.8";
section.style.transform = "translateY(20px)";
}
});
});
});
// Create stars throughout the page
function createStars(container, count) {
for (let i = 0; i < count; i++) {
const star = document.createElement("div");
star.classList.add("star");
// Random size (mostly small)
const sizeRand = Math.random();
if (sizeRand < 0.7) {
star.classList.add("small");
} else if (sizeRand < 0.9) {
star.classList.add("medium");
} else {
star.classList.add("large");
}
// Random position
star.style.left = `${Math.random() * 100}%`;
star.style.top = `${Math.random() * 100}%`;
// Random animation delay
star.style.animationDelay = `${Math.random() * 4}s`;
// Add to container
container.appendChild(star);
}
}
// Create denser star field specifically within the header
function createDenseStarsInHeader(header, count) {
for (let i = 0; i < count; i++) {
const star = document.createElement("div");
star.classList.add("dense-star");
// Random size (even smaller white points)
const size = Math.random() * 1.5 + 0.5;
star.style.width = `${size}px`;
star.style.height = `${size}px`;
// Brightness
const brightness = Math.random() * 0.5 + 0.5;
star.style.opacity = brightness;
// Random position within header
star.style.left = `${Math.random() * 100}%`;
star.style.top = `${Math.random() * 100}%`;
// Add twinkle effect to some stars
if (Math.random() > 0.7) {
star.style.animation = `twinkle ${
Math.random() * 3 + 2
}s infinite ease-in-out`;
star.style.animationDelay = `${Math.random() * 3}s`;
}
// Add to header
header.appendChild(star);
}
}