Spaces:
Running
Running
| // Product data - in a real scenario, this would come from an API | |
| const products = [ | |
| { | |
| id: 1, | |
| name: "Classic Hot Chocolate", | |
| price: "£12.99", | |
| image: "http://static.photos/food/400x400/1", | |
| hoverImage: "http://static.photos/food/400x400/2", | |
| rating: 5, | |
| flavor: "classic" | |
| }, | |
| { | |
| id: 2, | |
| name: "Zesty Orange Delight", | |
| price: "£14.99", | |
| image: "http://static.photos/food/400x400/3", | |
| hoverImage: "http://static.photos/food/400x400/4", | |
| rating: 5, | |
| flavor: "orange" | |
| }, | |
| { | |
| id: 3, | |
| name: "Mint Chocolate Dream", | |
| price: "£14.99", | |
| image: "http://static.photos/food/400x400/5", | |
| hoverImage: "http://static.photos/food/400x400/6", | |
| rating: 5, | |
| flavor: "mint" | |
| }, | |
| { | |
| id: 4, | |
| name: "Premium Cocoa Collection", | |
| price: "£24.99", | |
| image: "http://static.photos/food/400x400/7", | |
| hoverImage: "http://static.photos/food/400x400/8", | |
| rating: 5, | |
| flavor: "premium" | |
| } | |
| ]; | |
| // Load products into the grid | |
| document.addEventListener('DOMContentLoaded', function() { | |
| const productsGrid = document.getElementById('products-grid'); | |
| products.forEach(product => { | |
| const productCard = document.createElement('div'); | |
| productCard.className = 'product-card bg-white rounded-lg overflow-hidden shadow-md'; | |
| let flavorBadge = ''; | |
| if (product.flavor === 'orange') { | |
| flavorBadge = '<span class="absolute top-2 right-2 bg-zesty-orange text-white px-2 py-1 rounded-full text-xs font-semibold">Orange</span>'; | |
| } else if (product.flavor === 'mint') { | |
| flavorBadge = '<span class="absolute top-2 right-2 bg-mint-leaf text-white px-2 py-1 rounded-full text-xs font-semibold">Mint</span>'; | |
| } else if (product.flavor === 'premium') { | |
| flavorBadge = '<span class="absolute top-2 right-2 bg-luxury-gold text-white px-2 py-1 rounded-full text-xs font-semibold">Premium</span>'; | |
| } | |
| productCard.innerHTML = ` | |
| <div class="relative overflow-hidden"> | |
| <div class="relative h-64"> | |
| <img src="${product.image}" alt="${product.name}" class="w-full h-full object-cover transition-opacity duration-300"> | |
| <img src="${product.hoverImage}" alt="${product.name}" class="absolute top-0 left-0 w-full h-full object-cover opacity-0 hover:opacity-100 transition-opacity duration-300"> | |
| ${flavorBadge} | |
| </div> | |
| <div class="p-4"> | |
| <h3 class="font-semibold text-deep-cocoa mb-2">${product.name}</h3> | |
| <div class="flex items-center justify-between mb-2"> | |
| <span class="text-luxury-gold font-bold">${product.price}</span> | |
| <div class="flex text-luxury-gold"> | |
| ${'<i data-feather="star" class="w-4 h-4 fill-current"></i>'.repeat(product.rating)} | |
| </div> | |
| </div> | |
| <button class="quick-add-btn w-full bg-deep-cocoa hover:bg-milk-chocolate text-white py-2 rounded-lg transition duration-300"> | |
| Add to Cart | |
| </button> | |
| </div> | |
| </div> | |
| `; | |
| productsGrid.appendChild(productCard); | |
| }); | |
| // Re-initialize feather icons after adding new content | |
| feather.replace(); | |
| }); | |
| // Newsletter subscription | |
| document.addEventListener('DOMContentLoaded', function() { | |
| const newsletterForm = document.getElementById('newsletter-form'); | |
| if (newsletterForm) { | |
| newsletterForm.addEventListener('submit', function(e) { | |
| e.preventDefault(); | |
| const email = this.querySelector('input[type="email"]').value; | |
| alert(`Thank you for subscribing with ${email}! You'll receive our exclusive offers soon.`); | |
| this.reset(); | |
| }); | |
| } | |
| // Luxurious Drip Animation on Hero Button | |
| const heroBtn = document.querySelector('a[href="#products"]'); | |
| if (heroBtn) { | |
| heroBtn.classList.add('btn-melt'); | |
| } | |
| }); | |
| // Animate product cards on scroll | |
| const observerOptions = { threshold: 0.2 }; | |
| const productObserver = new IntersectionObserver((entries) => { | |
| entries.forEach(entry => { | |
| if (entry.isIntersecting) { | |
| entry.target.style.opacity = 1; | |
| entry.target.style.transform = 'translateY(0)'; | |
| } | |
| }); | |
| }, observerOptions); | |
| document.addEventListener('DOMContentLoaded', () => { | |
| const cards = document.querySelectorAll('.product-card'); | |
| cards.forEach(card => { | |
| card.style.opacity = 0; | |
| card.style.transform = 'translateY(30px)'; | |
| card.style.transition = 'opacity 0.6s ease, transform 0.6s ease'; | |
| productObserver.observe(card); | |
| }); | |
| }); | |