-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathscript.js
More file actions
166 lines (105 loc) · 4.47 KB
/
script.js
File metadata and controls
166 lines (105 loc) · 4.47 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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
// --- Scroll animasyonu için kartlar ve istatistikler seçiliyor ---
const cards = document.querySelectorAll(".card");
const stats = document.querySelectorAll(".stat-number");
// Sayfa scroll edildiğinde çalışan fonksiyon
function checkScroll() {
// --- Kart animasyonları ---
cards.forEach(card => {
const rect = card.getBoundingClientRect(); // Kartın ekrandaki konumunu al
// Kart ekrana girdiğinde görünür hale getir
if (rect.top < window.innerHeight - 100) {
card.classList.add("show"); // .show CSS animasyonunu tetikler
}
});
// --- İstatistik animasyonları ---
const statsSection = document.querySelector(".stats");
if (statsSection) {
const rect = statsSection.getBoundingClientRect();
// İstatistikler ekrana geldiğinde sadece 1 defa animasyonu çalıştır
if (rect.top < window.innerHeight - 200 && !statsSection.classList.contains("animated")) {
statsSection.classList.add("animated");
animateNumbers(); // Sayı animasyonunu başlat
}
}
// --- Yukarı çık butonu kontrolü ---
const backToTop = document.querySelector(".back-to-top");
if (window.pageYOffset > 300) {
backToTop.classList.add("visible"); // 300px aşağı kayınca buton görünür
} else {
backToTop.classList.remove("visible"); // Yukarı çıkınca kaybolur
}
} // checkScroll SONU..
//---------------------
// --- Scroll ve sayfa yükleme olaylarına checkScroll bağlanıyor ---
window.addEventListener("scroll", checkScroll);
window.addEventListener("load", checkScroll);
// --- İstatistik sayı animasyonu ---
function animateNumbers() {
const statNumbers = document.querySelectorAll(".stat-number");
const targets = [175, 63, 18000, 4500]; // Hedef sayılar
const durations = [2000, 1500, 2500, 2200]; // Animasyon süreleri (ms)
statNumbers.forEach((num, index) => {
let start = 0;
const end = targets[index];
const duration = durations[index];
const increment = end / (duration / 16); // FPS ~60 için 16ms hesap
const timer = setInterval(() => {
start += increment;
if (start >= end) {
clearInterval(timer); // Animasyon bitince durdur
num.textContent = end.toLocaleString(); // Sayıyı formatla
}
else {
num.textContent = Math.floor(start).toLocaleString();
}
}, 16);
});
} // animateNumbers SONU
// --- Tema değiştirme ---
const toggleBtn = document.querySelector(".theme-toggle");
toggleBtn.addEventListener("click", () => {
document.body.classList.toggle("light-theme"); // Tema değiştir
toggleBtn.textContent = document.body.classList.contains("light-theme") ? "☀️" : "🌙";
// Kullanıcı seçimini localStorage'da sakla
localStorage.setItem("theme", document.body.classList.contains("light-theme") ? "light" : "dark");
});
// --- Sayfa yüklendiğinde önceki tema kontrolü ---
if (localStorage.getItem("theme") === "light") {
document.body.classList.add("light-theme");
toggleBtn.textContent = "☀️";
}
// --- Mobil menü ---
const menuToggle = document.querySelector(".menu-toggle");
const navMenu = document.querySelector("nav ul");
menuToggle.addEventListener("click", () => {
navMenu.classList.toggle("show"); // Menü aç/kapat
});
// --- Smooth scroll (yumuşak kaydırma) ---
document.querySelectorAll("a[href^='#']").forEach(anchor => {
anchor.addEventListener("click", function(e) {
e.preventDefault();
const targetId = this.getAttribute("href");
if (targetId === "#") return; // Boş linkleri atla
const targetElement = document.querySelector(targetId);
if (targetElement) {
targetElement.scrollIntoView({
behavior: "smooth" // Yumuşak geçiş
});
// Mobil menü açıksa kapat
if (navMenu.classList.contains("show")) {
navMenu.classList.remove("show");
}
}
});
});
// --- Yukarı çık butonu tıklama olayı ---
document.querySelector(".back-to-top").addEventListener("click", (e) => {
e.preventDefault();
window.scrollTo({ top: 0, behavior: "smooth" }); // Yukarı kaydır
});
// --- Newsletter formu ---
document.querySelector(".newsletter-form").addEventListener("submit", (e) => {
e.preventDefault();
alert("Thanks for subscribing to NASA updates!"); // Kullanıcıya mesaj
e.target.reset(); // Formu sıfırla
});