|
1 | | - |
2 | | -// Typing effect (simple) |
| 1 | +// ---------------------------- |
| 2 | +// Typing effect |
| 3 | +// ---------------------------- |
3 | 4 | const typedText = "Hi, I'm SCode — a creative developer passionate about design, code, and user experience."; |
4 | 5 | const typedEl = document.getElementById('typed'); |
5 | 6 | let i = 0; |
6 | | -function typeWriter(){ if(i<=typedText.length){ typedEl.innerHTML = typedText.slice(0,i) + (i%2? '_':''); i++; setTimeout(typeWriter,28);} else { typedEl.innerHTML = typedText; } } |
7 | | -document.addEventListener('DOMContentLoaded', ()=>{ typeWriter(); }); |
8 | 7 |
|
| 8 | +function typeWriter() { |
| 9 | + if (!typedEl) return; |
| 10 | + if (i <= typedText.length) { |
| 11 | + typedEl.innerHTML = typedText.slice(0, i) + (i % 2 ? '_' : ''); |
| 12 | + i++; |
| 13 | + setTimeout(typeWriter, 28); |
| 14 | + } else { |
| 15 | + typedEl.innerHTML = typedText; |
| 16 | + } |
| 17 | +} |
| 18 | + |
| 19 | +document.addEventListener('DOMContentLoaded', () => { typeWriter(); }); |
| 20 | + |
| 21 | + |
| 22 | +// ---------------------------- |
9 | 23 | // Theme toggle (dark/light) with localStorage |
| 24 | +// ---------------------------- |
10 | 25 | const themeToggle = document.getElementById('themeToggle'); |
11 | | -themeToggle && themeToggle.addEventListener('click', ()=>{ |
12 | | - document.body.classList.toggle('light'); |
13 | | - themeToggle.textContent = document.body.classList.contains('light') ? '☀️' : '🌙'; |
14 | | - localStorage.setItem('scode_theme', document.body.classList.contains('light') ? 'light' : 'dark'); |
15 | | -}); |
16 | | -// Load saved theme |
17 | | -if(localStorage.getItem('scode_theme')==='light'){ document.body.classList.add('light'); if(themeToggle) themeToggle.textContent='☀️'; } |
| 26 | +if (themeToggle) { |
| 27 | + themeToggle.addEventListener('click', () => { |
| 28 | + document.body.classList.toggle('light-theme'); |
| 29 | + themeToggle.textContent = document.body.classList.contains('light-theme') ? '☀️' : '🌙'; |
| 30 | + localStorage.setItem('scode_theme', document.body.classList.contains('light-theme') ? 'light' : 'dark'); |
| 31 | + }); |
| 32 | +} |
| 33 | + |
| 34 | +// Load saved theme on page load |
| 35 | +if (localStorage.getItem('scode_theme') === 'light') { |
| 36 | + document.body.classList.add('light-theme'); |
| 37 | + if (themeToggle) themeToggle.textContent = '☀️'; |
| 38 | +} else { |
| 39 | + if (themeToggle) themeToggle.textContent = '🌙'; |
| 40 | +} |
18 | 41 |
|
19 | | -// Reveal on scroll |
| 42 | + |
| 43 | +// ---------------------------- |
| 44 | +// Reveal animations on scroll |
| 45 | +// ---------------------------- |
20 | 46 | const reveals = Array.from(document.querySelectorAll('.reveal')); |
21 | | -const obs = new IntersectionObserver((entries)=>{ |
22 | | - entries.forEach(ent=>{ if(ent.isIntersecting){ ent.target.classList.add('visible'); obs.unobserve(ent.target); } }); |
23 | | -},{threshold:0.12}); |
24 | | -reveals.forEach(r=>obs.observe(r)); |
| 47 | +const observer = new IntersectionObserver((entries) => { |
| 48 | + entries.forEach(entry => { |
| 49 | + if (entry.isIntersecting) { |
| 50 | + entry.target.classList.add('visible'); |
| 51 | + observer.unobserve(entry.target); |
| 52 | + } |
| 53 | + }); |
| 54 | +}, { threshold: 0.12 }); |
| 55 | + |
| 56 | +reveals.forEach(r => observer.observe(r)); |
| 57 | + |
25 | 58 |
|
26 | | -// Back to top button |
| 59 | +// ---------------------------- |
| 60 | +// Back-to-top button |
| 61 | +// ---------------------------- |
27 | 62 | const topBtn = document.getElementById('topBtn'); |
28 | | -window.addEventListener('scroll', ()=>{ if(window.scrollY>300) topBtn.style.display='flex'; else topBtn.style.display='none'; }); |
29 | | -topBtn && topBtn.addEventListener('click', ()=>{ window.scrollTo({top:0,behavior:'smooth'}); }); |
| 63 | +if (topBtn) topBtn.style.display = 'none'; |
| 64 | + |
| 65 | +window.addEventListener('scroll', () => { |
| 66 | + if (!topBtn) return; |
| 67 | + topBtn.style.display = window.scrollY > 300 ? 'flex' : 'none'; |
| 68 | +}); |
30 | 69 |
|
31 | | -// Smooth links handled by browser for external; internal anchors optional |
| 70 | +if (topBtn) { |
| 71 | + topBtn.addEventListener('click', () => { |
| 72 | + window.scrollTo({ top: 0, behavior: 'smooth' }); |
| 73 | + }); |
| 74 | +} |
0 commit comments