-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
74 lines (62 loc) · 2.24 KB
/
script.js
File metadata and controls
74 lines (62 loc) · 2.24 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
// ----------------------------
// Typing effect
// ----------------------------
const typedText = "Hi, I'm SCode — a creative developer passionate about design, code, and user experience.";
const typedEl = document.getElementById('typed');
let i = 0;
function typeWriter() {
if (!typedEl) return;
if (i <= typedText.length) {
typedEl.innerHTML = typedText.slice(0, i) + (i % 2 ? '_' : '');
i++;
setTimeout(typeWriter, 28);
} else {
typedEl.innerHTML = typedText;
}
}
document.addEventListener('DOMContentLoaded', () => { typeWriter(); });
// ----------------------------
// Theme toggle (dark/light) with localStorage
// ----------------------------
const themeToggle = document.getElementById('themeToggle');
if (themeToggle) {
themeToggle.addEventListener('click', () => {
document.body.classList.toggle('light-theme');
themeToggle.textContent = document.body.classList.contains('light-theme') ? '☀️' : '🌙';
localStorage.setItem('scode_theme', document.body.classList.contains('light-theme') ? 'light' : 'dark');
});
}
// Load saved theme on page load
if (localStorage.getItem('scode_theme') === 'light') {
document.body.classList.add('light-theme');
if (themeToggle) themeToggle.textContent = '☀️';
} else {
if (themeToggle) themeToggle.textContent = '🌙';
}
// ----------------------------
// Reveal animations on scroll
// ----------------------------
const reveals = Array.from(document.querySelectorAll('.reveal'));
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('visible');
observer.unobserve(entry.target);
}
});
}, { threshold: 0.12 });
reveals.forEach(r => observer.observe(r));
// ----------------------------
// Back-to-top button
// ----------------------------
const topBtn = document.getElementById('topBtn');
if (topBtn) topBtn.style.display = 'none';
window.addEventListener('scroll', () => {
if (!topBtn) return;
topBtn.style.display = window.scrollY > 300 ? 'flex' : 'none';
});
if (topBtn) {
topBtn.addEventListener('click', () => {
window.scrollTo({ top: 0, behavior: 'smooth' });
});
}