-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
executable file
·127 lines (116 loc) · 3.56 KB
/
script.js
File metadata and controls
executable file
·127 lines (116 loc) · 3.56 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
(function () {
const field = document.getElementById("starfield");
const COUNT =
parseInt(
getComputedStyle(document.documentElement).getPropertyValue(
"--star-count"
)
) || 120;
const speedFactor =
parseFloat(
getComputedStyle(document.documentElement).getPropertyValue(
"--speed-factor"
)
) || 0.1;
const inactiveDelay =
parseInt(
getComputedStyle(document.documentElement).getPropertyValue(
"--inactive-delay"
)
) || 10000;
const stars = [];
// Navbar'ı fade-in yapmak için visible sınıfı ekle
window.addEventListener('load', () => {
const navbar = document.querySelector('.bottom-nav');
if (navbar) {
navbar.classList.add('visible');
}
});
function rand(min, max) {
return Math.random() * (max - min) + min;
}
// Yıldızları oluştur
for (let i = 0; i < COUNT; i++) {
const s = document.createElement("div");
s.className = "star";
const size = Math.round(Math.pow(Math.random(), 1.8) * 3) + 1;
s.style.setProperty("--size", size + "px");
s.style.left = rand(0, 100) + "vw";
s.style.top = rand(0, 100) + "vh";
const durBase = rand(40, 140);
const dur = durBase / speedFactor;
const animName = Math.random() > 0.5 ? "driftX" : "driftY";
s.style.animation = `${animName} ${dur}s ease-in-out ${rand(
0,
dur
)}s infinite`;
s.style.opacity = rand(0.6, 1);
field.appendChild(s);
stars.push({ el: s, size, dur });
}
// Sparkle/parlama efekti
let sparkleRunning = true;
function startSparkles() {
sparkleRunning = true;
for (let i = 0; i < stars.length; i++) scheduleSparkle(stars[i]);
}
function stopSparkles() {
sparkleRunning = false;
}
function scheduleSparkle(starObj) {
if (!sparkleRunning) return;
const interval = rand(0.2, 2.5) * Math.max(1, starObj.dur / 20);
setTimeout(() => {
starObj.el.classList.add("pulse");
setTimeout(() => {
starObj.el.classList.remove("pulse");
scheduleSparkle(starObj);
}, rand(120, 800));
}, interval * 1000);
}
// Görünürlük kontrolü
let inactiveTimer = null;
let isVisible = false;
function setVisible(v) {
if (v === isVisible) return;
isVisible = v;
if (v) {
field.classList.remove("hidden");
field.classList.add("visible");
setTimeout(() => {
stars.forEach((s) => s.el.classList.add("glow"));
}, 120);
startSparkles();
} else {
stars.forEach((s) => s.el.classList.remove("glow"));
field.classList.remove("visible");
setTimeout(() => field.classList.add("hidden"), 20);
stopSparkles();
}
}
function resetInactiveTimer() {
clearTimeout(inactiveTimer);
setVisible(false);
inactiveTimer = setTimeout(() => setVisible(true), inactiveDelay);
}
inactiveTimer = setTimeout(() => setVisible(true), inactiveDelay);
let lastMoveTS = 0;
function onMove() {
const now = Date.now();
if (now - lastMoveTS < 50) return;
lastMoveTS = now;
resetInactiveTimer();
}
window.addEventListener("mousemove", onMove, { passive: true });
window.addEventListener("touchstart", onMove, { passive: true });
window.addEventListener("touchmove", onMove, { passive: true });
document.addEventListener("visibilitychange", () => {
if (document.hidden) stopSparkles();
else if (isVisible) startSparkles();
});
const prm = window.matchMedia("(prefers-reduced-motion: reduce)");
if (prm.matches) {
stars.forEach((s) => (s.el.style.animation = "none"));
}
field.classList.add("hidden");
})();