File size: 2,783 Bytes
4a6b087 | 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 70 71 72 73 74 75 76 77 | // Main application scripts
document.addEventListener('DOMContentLoaded', () => {
// Initialize tooltips
const tooltipElements = document.querySelectorAll('[data-tooltip]');
tooltipElements.forEach(el => {
const tooltipText = el.getAttribute('data-tooltip');
const tooltip = document.createElement('div');
tooltip.className = 'absolute hidden bg-gray-800 text-white text-xs rounded py-1 px-2 bottom-full mb-2 whitespace-nowrap';
tooltip.textContent = tooltipText;
el.appendChild(tooltip);
el.addEventListener('mouseenter', () => {
tooltip.classList.remove('hidden');
});
el.addEventListener('mouseleave', () => {
tooltip.classList.add('hidden');
});
});
// 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'
});
});
});
// Initialize animations
const animateOnScroll = () => {
const elements = document.querySelectorAll('.scroll-animate');
elements.forEach(el => {
const rect = el.getBoundingClientRect();
const isVisible = (rect.top <= window.innerHeight * 0.8);
if (isVisible && !el.classList.contains('animate-fade-in-up')) {
el.classList.add('animate-fade-in-up');
}
});
};
window.addEventListener('scroll', animateOnScroll);
animateOnScroll(); // Initial check
});
// Dark mode toggle functionality
class ThemeToggle {
static init() {
const toggle = document.getElementById('theme-toggle');
if (!toggle) return;
// Check for saved theme preference or use system preference
const savedTheme = localStorage.getItem('theme');
const systemDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
if (savedTheme === 'dark' || (!savedTheme && systemDark)) {
document.documentElement.classList.add('dark');
toggle.checked = true;
}
toggle.addEventListener('change', (e) => {
if (e.target.checked) {
document.documentElement.classList.add('dark');
localStorage.setItem('theme', 'dark');
} else {
document.documentElement.classList.remove('dark');
localStorage.setItem('theme', 'light');
}
});
}
}
// Initialize when DOM is loaded
document.addEventListener('DOMContentLoaded', ThemeToggle.init); |