Spaces:
Running
Running
File size: 2,072 Bytes
fa61c6b |
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 |
// Basic interactivity for portfolio
(function(){
const html = document.documentElement;
const themeToggle = document.getElementById('themeToggle');
const navToggle = document.getElementById('navToggle');
const navLinks = document.getElementById('navLinks');
const yearEl = document.getElementById('year');
const printBtn = document.getElementById('printBtn');
// Initialize year
if(yearEl){ yearEl.textContent = new Date().getFullYear(); }
// Theme persistence
const saved = localStorage.getItem('theme');
if(saved === 'light') html.classList.add('light');
function toggleTheme(){
html.classList.toggle('light');
localStorage.setItem('theme', html.classList.contains('light') ? 'light' : 'dark');
themeToggle.textContent = html.classList.contains('light') ? 'π' : 'π';
}
if(themeToggle){
themeToggle.addEventListener('click', toggleTheme);
themeToggle.textContent = html.classList.contains('light') ? 'π' : 'π';
}
// Mobile nav
if(navToggle){
navToggle.addEventListener('click', ()=>{
navLinks.classList.toggle('show');
});
}
if(navLinks){
navLinks.querySelectorAll('a').forEach(a=>{
a.addEventListener('click', ()=> navLinks.classList.remove('show'));
});
}
// Smooth scroll
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
const id = this.getAttribute('href');
if(id.length > 1){
e.preventDefault();
document.querySelector(id)?.scrollIntoView({behavior:'smooth'});
}
});
});
// Print to PDF
if(printBtn){
printBtn.addEventListener('click', ()=> window.print());
}
// Fade-in sections on scroll
const sections = document.querySelectorAll('.section');
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('visible');
}
});
}, { threshold: 0.1 });
sections.forEach(section => {
observer.observe(section);
});
})(); |