arefamer's picture
ุงู†ุดู‰ ู„ูŠ ุชุทุจูŠู‚ ุงู„ู‡ูŠูƒู„ ุฎุฑุงููŠ html css java
23d8f64 verified
Raw History Blame Contribute Delete
1.58 kB
// 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);
});