Spaces:
Running
Running
| document.addEventListener('DOMContentLoaded', function() { | |
| // Initialize tooltips | |
| const tooltipTriggers = document.querySelectorAll('[data-tooltip]'); | |
| tooltipTriggers.forEach(trigger => { | |
| const tooltip = document.createElement('div'); | |
| tooltip.className = 'hidden absolute z-50 w-max max-w-xs px-3 py-2 text-sm text-white bg-gray-800 rounded-md shadow-lg'; | |
| tooltip.textContent = trigger.getAttribute('data-tooltip'); | |
| trigger.parentNode.appendChild(tooltip); | |
| trigger.parentNode.style.position = 'relative'; | |
| trigger.addEventListener('mouseenter', () => { | |
| tooltip.classList.remove('hidden'); | |
| }); | |
| trigger.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' | |
| }); | |
| }); | |
| }); | |
| // Animate elements when they come into view | |
| const animateOnScroll = () => { | |
| const elements = document.querySelectorAll('.fade-in, .slide-up'); | |
| elements.forEach(element => { | |
| const elementPosition = element.getBoundingClientRect().top; | |
| const windowHeight = window.innerHeight; | |
| if (elementPosition < windowHeight - 100) { | |
| element.style.opacity = '1'; | |
| element.style.transform = 'translateY(0)'; | |
| } | |
| }); | |
| }; | |
| window.addEventListener('scroll', animateOnScroll); | |
| animateOnScroll(); // Run once on load | |
| }); | |
| // API integration for crypto prices | |
| async function fetchCryptoPrices() { | |
| try { | |
| const response = await fetch('https://api.coingecko.com/api/v3/simple/price?ids=bitcoin,ethereum&vs_currencies=usd'); | |
| const data = await response.json(); | |
| if (data.bitcoin && data.ethereum) { | |
| document.querySelectorAll('.btc-price').forEach(el => { | |
| el.textContent = `$${data.bitcoin.usd.toLocaleString()}`; | |
| }); | |
| document.querySelectorAll('.eth-price').forEach(el => { | |
| el.textContent = `$${data.ethereum.usd.toLocaleString()}`; | |
| }); | |
| } | |
| } catch (error) { | |
| console.error('Error fetching crypto prices:', error); | |
| } | |
| } | |
| // Call the function when the page loads | |
| window.addEventListener('load', fetchCryptoPrices); |