pixelpulse-pro / script.js
jonesfernandes's picture
Deixe o site moderno, bonito e responsivo
27d3502 verified
// Theme switcher functionality
document.addEventListener('DOMContentLoaded', () => {
// Check for saved theme preference or use system preference
const savedTheme = localStorage.getItem('theme') ||
(window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light');
// Apply the saved theme
document.documentElement.classList.toggle('dark', savedTheme === 'dark');
// Theme toggle button functionality
const themeToggle = document.getElementById('theme-toggle');
if (themeToggle) {
themeToggle.addEventListener('click', () => {
const isDark = document.documentElement.classList.toggle('dark');
localStorage.setItem('theme', isDark ? 'dark' : 'light');
themeToggle.innerHTML = isDark ?
'<i data-feather="sun"></i>' :
'<i data-feather="moon"></i>';
feather.replace();
});
// Set initial icon
themeToggle.innerHTML = savedTheme === 'dark' ?
'<i data-feather="sun"></i>' :
'<i data-feather="moon"></i>';
feather.replace();
}
// Animate elements on scroll
const animateOnScroll = () => {
const elements = document.querySelectorAll('.fade-in, .slide-up');
elements.forEach(el => {
const elementPosition = el.getBoundingClientRect().top;
const windowHeight = window.innerHeight;
if (elementPosition < windowHeight - 100) {
el.style.opacity = '1';
el.style.transform = 'translateY(0)';
}
});
};
// Initial check
animateOnScroll();
// Check on scroll
window.addEventListener('scroll', animateOnScroll);
});