Spaces:
Running
Running
File size: 2,300 Bytes
70a2d3b |
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 |
// Count up animation
function animateValue(el, start, end, duration) {
let startTimestamp = null;
const step = (timestamp) => {
if (!startTimestamp) startTimestamp = timestamp;
const progress = Math.min((timestamp - startTimestamp) / duration, 1);
el.innerHTML = Math.floor(progress * (end - start) + start).toLocaleString();
if (progress < 1) {
window.requestAnimationFrame(step);
}
};
window.requestAnimationFrame(step);
}
// Enhanced DOMContentLoaded
document.addEventListener('DOMContentLoaded', () => {
// Check for saved theme preference or use preferred color scheme
const savedTheme = localStorage.getItem('theme') ||
(window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light');
document.documentElement.classList.add(savedTheme);
// Set up theme toggle button
const themeToggle = document.querySelector('.theme-toggle');
if (themeToggle) {
themeToggle.addEventListener('click', () => {
const html = document.documentElement;
const isDark = html.classList.contains('dark');
if (isDark) {
html.classList.remove('dark');
localStorage.setItem('theme', 'light');
} else {
html.classList.add('dark');
localStorage.setItem('theme', 'dark');
}
feather.replace();
});
}
// Animate balance count-up
const balanceEl = document.querySelector('.count-up');
if (balanceEl) {
const target = parseInt(balanceEl.dataset.target);
animateValue(balanceEl, 0, target, 2000);
}
// Stagger transaction animations
document.querySelectorAll('.transaction-item').forEach((item, i) => {
setTimeout(() => {
item.style.opacity = '1';
}, i * 150);
});
// Add hover effects to cards
const cards = document.querySelectorAll('.transaction-item, .quick-action');
cards.forEach(card => {
card.addEventListener('mouseenter', () => {
card.classList.add('shadow-lg');
});
card.addEventListener('mouseleave', () => {
card.classList.remove('shadow-lg');
});
});
}); |