{ img.classList.remove('active-thumbnail'); }); } } function selectSize(element) { var parent = element.parentElement; var variantOptions = parent.querySelectorAll('.variant-option'); for (var i = 0; i < variantOptions.length; i++) { variantOptions[i].classList.remove('active'); } element.classList.add('active'); var value = element.getAttribute('data-option'); document.querySelector('input.size_value').value = value; document.querySelector('.size_value_text').textContent =value; element.style.transform = 'translateY(-5px)'; setTimeout(function() { element.style.transform = 'translateY(0)'; }, 300); } // Change product quantity function changeQuantity(change) { var input = document.querySelector('.quantity-input'); var value = parseInt(input.value) + change; if (value < 1) value = 1; if (value > 10) value = 10; input.value = value; } // Add to cart button animation var addToCartBtn = document.querySelector('.btn-add-to-cart'); if (addToCartBtn) { addToCartBtn.addEventListener('click', function() { this.innerHTML = ' ADDED TO CART'; // Create confetti effect var rect = this.getBoundingClientRect(); var centerX = rect.left + this.offsetWidth/2; var centerY = rect.top + this.offsetHeight/2; for(var i = 0; i < 10; i++) { createConfetti(centerX, centerY); } var self = this; setTimeout(function() { self.innerHTML = ' BUY NOW'; }, 2000); }); } // Create confetti effect function createConfetti(x, y) { var confetti = document.createElement('div'); confetti.style.position = 'fixed'; confetti.style.width = '8px'; confetti.style.height = '8px'; var colors = ['#4facfe', '#00f2fe', '#7c3aed', '#f43f5e']; confetti.style.backgroundColor = colors[Math.floor(Math.random() * colors.length)]; confetti.style.borderRadius = '50%'; confetti.style.pointerEvents = 'none'; confetti.style.zIndex = '9999'; confetti.style.left = x + 'px'; confetti.style.top = y + 'px'; document.body.appendChild(confetti); var angle = Math.random() * Math.PI * 2; var velocity = 2 + Math.random() * 3; var lifetime = 500 + Math.random() * 500; var dx = Math.cos(angle) * velocity; var dy = Math.sin(angle) * velocity; var posX = x; var posY = y; var opacity = 1; function animate() { posX += dx; posY += dy + 0.5; // slight downward drift opacity -= 0.02; confetti.style.left = posX + 'px'; confetti.style.top = posY + 'px'; confetti.style.opacity = opacity; if(opacity > 0) { requestAnimationFrame(animate); } else { confetti.remove(); } }; requestAnimationFrame(animate); } // Wishlist button toggle var wishlistBtn = document.querySelector('.btn-wishlist'); if (wishlistBtn) { wishlistBtn.addEventListener('click', function() { var icon = this.querySelector('i'); if (icon.classList.contains('far')) { icon.classList.remove('far'); icon.classList.add('fas'); this.style.color = '#f43f5e'; this.style.borderColor = '#f43f5e'; this.style.transform = 'scale(1.2)'; } else { icon.classList.remove('fas'); icon.classList.add('far'); this.style.color = '#94a3b8'; this.style.borderColor = '#e2e8f0'; this.style.transform = 'scale(1)'; } var self = this; setTimeout(function() { self.style.transform = 'scale(1)'; }, 300); }); } // Add hover effect to related products var relatedProducts = document.querySelectorAll('.related-product-card'); for (var i = 0; i < relatedProducts.length; i++) { relatedProducts[i].addEventListener('mouseenter', function() { var img = this.querySelector('.related-product-img'); img.style.transform = 'scale(1.05)'; }); relatedProducts[i].addEventListener('mouseleave', function() { var img = this.querySelector('.related-product-img'); img.style.transform = 'scale(1)'; }); }