markjr's picture
bumd.fun
00f04d0 verified
Raw
History Blame Contribute Delete
3.98 kB
// Main JavaScript for BumdFun
// Initialize when DOM is loaded
document.addEventListener('DOMContentLoaded', function() {
// Add smooth scroll behavior for anchor links
const anchorLinks = document.querySelectorAll('a[href^="#"]');
anchorLinks.forEach(link => {
link.addEventListener('click', function(e) {
e.preventDefault();
const targetId = this.getAttribute('href');
const targetElement = document.querySelector(targetId);
if (targetElement) {
targetElement.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
}
});
});
// Add intersection observer for fade-in animations
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
};
const observer = new IntersectionObserver(function(entries) {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('opacity-100', 'translate-y-0');
entry.target.classList.remove('opacity-0', 'translate-y-8');
}
});
}, observerOptions);
// Observe elements for animation
const animatedElements = document.querySelectorAll('.feature-card, .explore-card');
animatedElements.forEach(el => {
el.classList.add('opacity-0', 'translate-y-8', 'transition-all', 'duration-700');
observer.observe(el);
});
// Parallax effect for hero section
window.addEventListener('scroll', function() {
const scrolled = window.pageYOffset;
const parallaxElements = document.querySelectorAll('.parallax');
parallaxElements.forEach(el => {
const speed = el.dataset.speed || 0.5;
el.style.transform = `translateY(${scrolled * speed}px)`;
});
// Theme toggle functionality (for future implementation)
const themeToggle = document.querySelector('#theme-toggle');
if (themeToggle) {
themeToggle.addEventListener('click', function() {
document.body.classList.toggle('dark');
// Save theme preference to localStorage
const isDark = document.body.classList.contains('dark');
localStorage.setItem('bumdfun-theme', isDark ? 'dark' : 'light');
});
}
// Check for saved theme preference
const savedTheme = localStorage.getItem('bumdfun-theme');
if (savedTheme === 'dark') {
document.body.classList.add('dark');
}
// Initialize tooltips for icons
const initTooltips = () => {
const tooltipElements = document.querySelectorAll('[data-tooltip]');
tooltipElements.forEach(el => {
el.addEventListener('mouseenter', function() {
const tooltip = document.createElement('div');
tooltip.className = 'absolute z-50 px-3 py-2 text-sm font-medium text-white bg-gray-900 rounded-lg shadow-sm tooltip';
tooltip.textContent = this.dataset.tooltip;
document.body.appendChild(tooltip);
const rect = this.getBoundingClientRect();
tooltip.style.left = `${rect.left + window.scrollX}px`;
tooltip.style.top = `${rect.top + window.scrollY - 40}px`;
this.addEventListener('mouseleave', function() {
tooltip.remove();
}, { once: true });
});
});
};
initTooltips();
});
// Utility function for API calls
async function fetchBumdData(endpoint) {
try {
const response = await fetch(`https://api.bumdfun.com/${endpoint}`);
if (!response.ok) {
throw new Error('Network response was not ok');
}
return await response.json();
} catch (error) {
console.error('Error fetching data:', error);
return null;
}
}
// Export for use in components
window.BumdFunUtils = {
fetchBumdData
};