Spaces:
Running
Running
Download script.js from lkadmin/kartracing-arena: direct link, hf CLI and curl.
- Browser
- Download file 6.31 kB
-
https://huggingface.co/spaces/lkadmin/kartracing-arena/resolve/main/script.js
- Command line
-
hf download hf://spaces/lkadmin/kartracing-arena/script.js
-
curl -L -o script.js https://huggingface.co/spaces/lkadmin/kartracing-arena/resolve/main/script.js
6.31 kB
| // Initialize when DOM is loaded | |
| document.addEventListener('DOMContentLoaded', function() { | |
| // Hide loader after page loads | |
| setTimeout(() => { | |
| const loader = document.getElementById('loader'); | |
| loader.classList.add('hidden'); | |
| setTimeout(() => loader.remove(), 500); | |
| }, 1000); | |
| // Smooth scroll for anchor links | |
| document.querySelectorAll('a[href^="#"]').forEach(anchor => { | |
| anchor.addEventListener('click', function (e) { | |
| e.preventDefault(); | |
| const target = document.querySelector(this.getAttribute('href')); | |
| if (target) { | |
| target.scrollIntoView({ | |
| behavior: 'smooth', | |
| block: 'start' | |
| }); | |
| } | |
| }); | |
| }); | |
| // Booking form submission | |
| const bookingForm = document.getElementById('bookingForm'); | |
| if (bookingForm) { | |
| bookingForm.addEventListener('submit', function(e) { | |
| e.preventDefault(); | |
| // Create success notification | |
| const notification = document.createElement('div'); | |
| notification.className = 'fixed top-4 right-4 bg-gradient-to-r from-orange-500 to-fuchsia-500 text-white px-6 py-4 rounded-lg shadow-2xl z-50 transform translate-x-full transition-transform'; | |
| notification.innerHTML = ` | |
| <div class="flex items-center gap-3"> | |
| <i data-feather="check-circle" class="w-6 h-6"></i> | |
| <div> | |
| <p class="font-bold">Booking Confirmed!</p> | |
| <p class="text-sm opacity-90">We'll send you a confirmation email soon.</p> | |
| </div> | |
| </div> | |
| `; | |
| document.body.appendChild(notification); | |
| feather.replace(); | |
| // Animate in | |
| setTimeout(() => { | |
| notification.style.transform = 'translateX(0)'; | |
| }, 100); | |
| // Remove after 5 seconds | |
| setTimeout(() => { | |
| notification.style.transform = 'translateX(120%)'; | |
| setTimeout(() => notification.remove(), 300); | |
| }, 5000); | |
| // Reset form | |
| bookingForm.reset(); | |
| }); | |
| } | |
| // Intersection Observer for animations | |
| const observerOptions = { | |
| threshold: 0.1, | |
| rootMargin: '0px 0px -50px 0px' | |
| }; | |
| const observer = new IntersectionObserver((entries) => { | |
| entries.forEach(entry => { | |
| if (entry.isIntersecting) { | |
| entry.target.style.opacity = '1'; | |
| entry.target.style.transform = 'translateY(0)'; | |
| } | |
| }); | |
| }, observerOptions); | |
| // Observe all sections | |
| document.querySelectorAll('section').forEach(section => { | |
| section.style.opacity = '0'; | |
| section.style.transform = 'translateY(30px)'; | |
| section.style.transition = 'opacity 0.6s ease, transform 0.6s ease'; | |
| observer.observe(section); | |
| }); | |
| // Gallery image viewer | |
| const galleryImages = document.querySelectorAll('#gallery img'); | |
| galleryImages.forEach(img => { | |
| img.addEventListener('click', function() { | |
| const viewer = document.createElement('div'); | |
| viewer.className = 'fixed inset-0 bg-black bg-opacity-90 z-50 flex items-center justify-center p-4'; | |
| viewer.innerHTML = ` | |
| <div class="relative max-w-4xl max-h-full"> | |
| <img src="${this.src}" alt="${this.alt}" class="max-w-full max-h-full rounded-lg"> | |
| <button class="absolute top-4 right-4 text-white bg-black bg-opacity-50 rounded-full p-2 hover:bg-opacity-75"> | |
| <i data-feather="x" class="w-6 h-6"></i> | |
| </button> | |
| </div> | |
| `; | |
| document.body.appendChild(viewer); | |
| feather.replace(); | |
| viewer.addEventListener('click', function(e) { | |
| if (e.target === viewer || e.target.closest('button')) { | |
| viewer.remove(); | |
| } | |
| }); | |
| }); | |
| }); | |
| // Dynamic typing effect for hero title | |
| const heroTitle = document.querySelector('h1'); | |
| if (heroTitle) { | |
| const text = heroTitle.textContent; | |
| heroTitle.textContent = ''; | |
| let index = 0; | |
| const typeWriter = () => { | |
| if (index < text.length) { | |
| heroTitle.textContent += text.charAt(index); | |
| index++; | |
| setTimeout(typeWriter, 100); | |
| } | |
| }; | |
| setTimeout(typeWriter, 500); | |
| } | |
| // Add ripple effect to buttons | |
| document.querySelectorAll('button').forEach(button => { | |
| button.classList.add('ripple'); | |
| }); | |
| // Parallax effect for hero section | |
| window.addEventListener('scroll', () => { | |
| const scrolled = window.pageYOffset; | |
| const parallax = document.querySelector('.hero-image'); | |
| if (parallax) { | |
| parallax.style.transform = `translateY(${scrolled * 0.5}px)`; | |
| } | |
| }); | |
| // Counter animation | |
| function animateCounter(element, target, duration = 2000) { | |
| let start = 0; | |
| const increment = target / (duration / 16); | |
| const updateCounter = () => { | |
| start += increment; | |
| if (start < target) { | |
| element.textContent = Math.floor(start); | |
| requestAnimationFrame(updateCounter); | |
| } else { | |
| element.textContent = target; | |
| } | |
| }; | |
| updateCounter(); | |
| } | |
| // Observe counter elements | |
| const counters = document.querySelectorAll('.counter'); | |
| const counterObserver = new IntersectionObserver((entries) => { | |
| entries.forEach(entry => { | |
| if (entry.isIntersecting && !entry.target.classList.contains('counted')) { | |
| const target = parseInt(entry.target.getAttribute('data-target')); | |
| animateCounter(entry.target, target); | |
| entry.target.classList.add('counted'); | |
| } | |
| }); | |
| }, { threshold: 0.5 }); | |
| counters.forEach(counter => { | |
| counterObserver.observe(counter); | |
| }); | |
| }); |