Spaces:
Running
Running
Download script.js from namlt/motoride-pro: direct link, hf CLI and curl.
- Browser
- Download file 10.1 kB
-
https://huggingface.co/spaces/namlt/motoride-pro/resolve/main/script.js
- Command line
-
hf download hf://spaces/namlt/motoride-pro/script.js
-
curl -L -o script.js https://huggingface.co/spaces/namlt/motoride-pro/resolve/main/script.js
10.1 kB
| // Bike Data | |
| const bikes = [ | |
| { | |
| id: 1, | |
| name: "Thunder Beast X1", | |
| category: "Sport", | |
| price: "$24,999", | |
| engine: "1000cc", | |
| power: "200 HP", | |
| image: "http://static.photos/technology/640x360/101" | |
| }, | |
| { | |
| id: 2, | |
| name: "Cruiser Deluxe Pro", | |
| category: "Cruiser", | |
| price: "$19,999", | |
| engine: "1200cc", | |
| power: "150 HP", | |
| image: "http://static.photos/technology/640x360/102" | |
| }, | |
| { | |
| id: 3, | |
| name: "Adventure Rider 500", | |
| category: "Adventure", | |
| price: "$22,499", | |
| engine: "850cc", | |
| power: "120 HP", | |
| image: "http://static.photos/technology/640x360/103" | |
| }, | |
| { | |
| id: 4, | |
| name: "Urban Street Fighter", | |
| category: "Street", | |
| price: "$16,999", | |
| engine: "750cc", | |
| power: "110 HP", | |
| image: "http://static.photos/technology/640x360/104" | |
| }, | |
| { | |
| id: 5, | |
| name: "Electric E-Storm", | |
| category: "Electric", | |
| price: "$28,999", | |
| engine: "Electric", | |
| power: "250 HP", | |
| image: "http://static.photos/technology/640x360/105" | |
| }, | |
| { | |
| id: 6, | |
| name: "Classic Vintage 900", | |
| category: "Classic", | |
| price: "$18,499", | |
| engine: "900cc", | |
| power: "95 HP", | |
| image: "http://static.photos/technology/640x360/106" | |
| } | |
| ]; | |
| // Initialize Page | |
| document.addEventListener('DOMContentLoaded', function() { | |
| // Hide loader | |
| setTimeout(() => { | |
| const loader = document.getElementById('loader'); | |
| loader.classList.add('hidden'); | |
| setTimeout(() => { | |
| loader.style.display = 'none'; | |
| }, 500); | |
| }, 1500); | |
| // Load bikes | |
| loadBikes(); | |
| // Initialize counters | |
| initCounters(); | |
| // Setup form submission | |
| setupContactForm(); | |
| // Setup scroll effects | |
| setupScrollEffects(); | |
| }); | |
| // Load Bikes | |
| function loadBikes() { | |
| const bikesGrid = document.getElementById('bikesGrid'); | |
| bikes.forEach((bike, index) => { | |
| const bikeCard = document.createElement('div'); | |
| bikeCard.className = 'bike-card bg-primary-800 rounded-xl overflow-hidden shadow-xl hover:shadow-2xl cursor-pointer'; | |
| bikeCard.innerHTML = ` | |
| <div class="relative overflow-hidden h-48"> | |
| <img src="${bike.image}" alt="${bike.name}" class="bike-image w-full h-full object-cover"> | |
| <div class="absolute top-4 right-4 bg-accent-500 text-white px-3 py-1 rounded-full text-sm font-bold"> | |
| ${bike.category} | |
| </div> | |
| </div> | |
| <div class="p-6"> | |
| <h3 class="text-2xl font-bold mb-2">${bike.name}</h3> | |
| <div class="flex justify-between items-center mb-4"> | |
| <span class="text-3xl font-bold text-accent-500">${bike.price}</span> | |
| <div class="flex space-x-2"> | |
| <span class="text-sm text-primary-400">${bike.engine}</span> | |
| <span class="text-sm text-primary-400">•</span> | |
| <span class="text-sm text-primary-400">${bike.power}</span> | |
| </div> | |
| </div> | |
| <button onclick="viewBikeDetails(${bike.id})" class="w-full px-4 py-2 bg-primary-700 hover:bg-accent-500 text-white font-bold rounded-lg transition-all duration-300"> | |
| View Details | |
| </button> | |
| </div> | |
| `; | |
| bikesGrid.appendChild(bikeCard); | |
| // Animate cards on scroll | |
| setTimeout(() => { | |
| bikeCard.style.opacity = '0'; | |
| bikeCard.style.transform = 'translateY(20px)'; | |
| bikeCard.style.transition = 'all 0.5s ease'; | |
| setTimeout(() => { | |
| bikeCard.style.opacity = '1'; | |
| bikeCard.style.transform = 'translateY(0)'; | |
| }, 100 * index); | |
| }, 100); | |
| }); | |
| } | |
| // View Bike Details | |
| function viewBikeDetails(bikeId) { | |
| const bike = bikes.find(b => b.id === bikeId); | |
| if (bike) { | |
| showNotification(`Viewing details for ${bike.name}`); | |
| // In a real app, this would navigate to a details page or open a modal | |
| } | |
| } | |
| // Initialize Counter Animation | |
| function initCounters() { | |
| const counters = document.querySelectorAll('.counter'); | |
| const speed = 200; | |
| const observerOptions = { | |
| threshold: 0.5 | |
| }; | |
| const observer = new IntersectionObserver((entries) => { | |
| entries.forEach(entry => { | |
| if (entry.isIntersecting) { | |
| const counter = entry.target; | |
| const target = +counter.getAttribute('data-target'); | |
| const increment = target / speed; | |
| const updateCounter = () => { | |
| const current = +counter.innerText; | |
| if (current < target) { | |
| counter.innerText = Math.ceil(current + increment); | |
| setTimeout(updateCounter, 10); | |
| } else { | |
| counter.innerText = target; | |
| } | |
| }; | |
| updateCounter(); | |
| observer.unobserve(counter); | |
| } | |
| }); | |
| }, observerOptions); | |
| counters.forEach(counter => { | |
| observer.observe(counter); | |
| }); | |
| } | |
| // Setup Contact Form | |
| function setupContactForm() { | |
| const form = document.getElementById('contactForm'); | |
| if (form) { | |
| form.addEventListener('submit', function(e) { | |
| e.preventDefault(); | |
| // Show success notification | |
| showNotification('Message sent successfully! We\'ll get back to you soon.'); | |
| // Reset form | |
| form.reset(); | |
| }); | |
| } | |
| } | |
| // Setup Scroll Effects | |
| function setupScrollEffects() { | |
| let lastScroll = 0; | |
| const navbar = document.querySelector('nav'); | |
| window.addEventListener('scroll', () => { | |
| const currentScroll = window.pageYOffset; | |
| // Add shadow on scroll | |
| if (currentScroll > 10) { | |
| navbar.classList.add('shadow-lg', 'navbar-scrolled'); | |
| } else { | |
| navbar.classList.remove('shadow-lg', 'navbar-scrolled'); | |
| } | |
| lastScroll = currentScroll; | |
| }); | |
| } | |
| // Smooth Scroll to Section | |
| function scrollToSection(sectionId) { | |
| const section = document.getElementById(sectionId); | |
| if (section) { | |
| section.scrollIntoView({ behavior: 'smooth', block: 'start' }); | |
| } | |
| } | |
| // Show Notification | |
| function showNotification(message) { | |
| // Create notification element | |
| const notification = document.createElement('div'); | |
| notification.className = 'fixed bottom-4 right-4 bg-accent-500 text-white px-6 py-3 rounded-lg shadow-lg z-50 transform translate-y-20 transition-transform duration-300'; | |
| notification.textContent = message; | |
| document.body.appendChild(notification); | |
| // Show notification | |
| setTimeout(() => { | |
| notification.style.transform = 'translateY(0)'; | |
| }, 100); | |
| // Hide notification after 3 seconds | |
| setTimeout(() => { | |
| notification.style.transform = 'translateY(20px)'; | |
| setTimeout(() => { | |
| document.body.removeChild(notification); | |
| }, 300); | |
| }, 3000); | |
| } | |
| // Filter Bikes by Category | |
| function filterBikes(category) { | |
| const filteredBikes = category === 'all' | |
| ? bikes | |
| : bikes.filter(bike => bike.category.toLowerCase() === category.toLowerCase()); | |
| const bikesGrid = document.getElementById('bikesGrid'); | |
| bikesGrid.innerHTML = ''; | |
| filteredBikes.forEach((bike, index) => { | |
| const bikeCard = document.createElement('div'); | |
| bikeCard.className = 'bike-card bg-primary-800 rounded-xl overflow-hidden shadow-xl hover:shadow-2xl cursor-pointer'; | |
| bikeCard.innerHTML = ` | |
| <div class="relative overflow-hidden h-48"> | |
| <img src="${bike.image}" alt="${bike.name}" class="bike-image w-full h-full object-cover"> | |
| <div class="absolute top-4 right-4 bg-accent-500 text-white px-3 py-1 rounded-full text-sm font-bold"> | |
| ${bike.category} | |
| </div> | |
| </div> | |
| <div class="p-6"> | |
| <h3 class="text-2xl font-bold mb-2">${bike.name}</h3> | |
| <div class="flex justify-between items-center mb-4"> | |
| <span class="text-3xl font-bold text-accent-500">${bike.price}</span> | |
| <div class="flex space-x-2"> | |
| <span class="text-sm text-primary-400">${bike.engine}</span> | |
| <span class="text-sm text-primary-400">•</span> | |
| <span class="text-sm text-primary-400">${bike.power}</span> | |
| </div> | |
| </div> | |
| <button onclick="viewBikeDetails(${bike.id})" class="w-full px-4 py-2 bg-primary-700 hover:bg-accent-500 text-white font-bold rounded-lg transition-all duration-300"> | |
| View Details | |
| </button> | |
| </div> | |
| `; | |
| bikesGrid.appendChild(bikeCard); | |
| }); | |
| } | |
| // Add to Cart (for future implementation) | |
| function addToCart(bikeId) { | |
| const bike = bikes.find(b => b.id === bikeId); | |
| if (bike) { | |
| showNotification(`${bike.name} added to wishlist!`); | |
| } | |
| } | |
| // Search Bikes | |
| function searchBikes(query) { | |
| const filteredBikes = bikes.filter(bike => | |
| bike.name.toLowerCase().includes(query.toLowerCase()) || | |
| bike.category.toLowerCase().includes(query.toLowerCase()) | |
| ); | |
| if (filteredBikes.length === 0) { | |
| showNotification('No bikes found matching your search.'); | |
| } else { | |
| // Update the grid with filtered results | |
| const bikesGrid = document.getElementById('bikesGrid'); | |
| bikesGrid.innerHTML = ''; | |
| filteredBikes.forEach((bike, index) => { | |
| // Reuse the bike card creation logic | |
| }); | |
| } | |
| } |