File size: 1,583 Bytes
55733a2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23d8f64
 
 
 
 
 
 
 
 
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
// Smooth scrolling for anchor links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
  anchor.addEventListener('click', function (e) {
    e.preventDefault();
    document.querySelector(this.getAttribute('href')).scrollIntoView({
      behavior: 'smooth'
    });
  });
});

// Theme toggle functionality
const themeToggle = document.getElementById('theme-toggle');
if (themeToggle) {
  themeToggle.addEventListener('click', () => {
    document.body.classList.toggle('dark-theme');
    localStorage.setItem('theme', document.body.classList.contains('dark-theme') ? 'dark' : 'light');
  });
}

// Initialize theme from localStorage
if (localStorage.getItem('theme') === 'dark') {
  document.body.classList.add('dark-theme');
}

// Dynamic year for footer
document.querySelectorAll('.current-year').forEach(el => {
  el.textContent = new Date().getFullYear();
});
// Animation on scroll
const animateOnScroll = () => {
  const elements = document.querySelectorAll('.animate');
  elements.forEach(el => {
    const elementPosition = el.getBoundingClientRect().top;
    const screenPosition = window.innerHeight / 1.3;
    if (elementPosition < screenPosition) {
      el.classList.add('animated');
    }
  });
};

window.addEventListener('scroll', animateOnScroll);
window.addEventListener('load', animateOnScroll);

// Weather widget API key (replace with your own)
const WEATHER_API_KEY = 'YOUR_OPENWEATHERMAP_API_KEY';

// Initialize weather widgets
document.querySelectorAll('weather-widget').forEach(widget => {
  widget.setAttribute('api-key', WEATHER_API_KEY);
});