-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
82 lines (76 loc) · 2.63 KB
/
script.js
File metadata and controls
82 lines (76 loc) · 2.63 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
// Fade-in on scroll (optional if you already had it)
const fxSections = document.querySelectorAll('.section, .card, .project-card, .cardish');
const onScroll = () => {
const trigger = window.innerHeight * 0.85;
fxSections.forEach(el => {
const top = el.getBoundingClientRect().top;
if (top < trigger) el.classList.add('visible');
});
};
window.addEventListener('scroll', onScroll);
onScroll();
// Dark / Light toggle with memory
const toggleBtn = document.getElementById('theme-toggle');
if (toggleBtn) {
const saved = localStorage.getItem('theme');
if (saved === 'dark') {
document.body.classList.add('dark');
toggleBtn.textContent = '☀️';
}
toggleBtn.addEventListener('click', () => {
document.body.classList.toggle('dark');
const dark = document.body.classList.contains('dark');
toggleBtn.textContent = dark ? '☀️' : '🌙';
localStorage.setItem('theme', dark ? 'dark' : 'light');
});
}
// Formspree AJAX submit (stays on page and shows status)
const form = document.getElementById('fs-form');
const statusEl = document.getElementById('fs-status');
if (form) {
form.addEventListener('submit', async (e) => {
e.preventDefault();
statusEl.textContent = 'Sending...';
try {
const formData = new FormData(form);
const res = await fetch(form.action, {
method: form.method,
headers: { 'Accept': 'application/json' },
body: formData
});
if (res.ok) {
form.reset();
statusEl.textContent = 'Thanks! Your message has been sent.';
} else {
statusEl.textContent = 'Oops, something went wrong. Please try again.';
}
} catch (err) {
statusEl.textContent = 'Network error. Please try again.';
}
});
}
//Footer year
document.getElementById('year').textContent = new Date().getFullYear();
// ===============================
// // Theme Toggle (Dark / Light)
// // ===============================
// const toggle = document.getElementById("theme-toggle");
// toggle.addEventListener("click", () => {
// document.body.classList.toggle("light-mode");
// toggle.textContent = document.body.classList.contains("light-mode") ? "🌞" : "🌙";
// });
// // ===============================
// // Scroll Smooth for Internal Links
// // ===============================
// document.querySelectorAll('a[href^="#"]').forEach(anchor => {
// anchor.addEventListener("click", function (e) {
// e.preventDefault();
// const target = document.querySelector(this.getAttribute("href"));
// if (target) {
// target.scrollIntoView({
// behavior: "smooth",
// block: "start",
// });
// }
// });
// });