Grok 4.1 Fast· xai
Frontier Reasoning Traces
Create an interactive photo gallery that enlarges images smoothly on hover and returns…
- User
Create an interactive photo gallery that enlarges images smoothly on hover and returns them to their original size when clicked again using HTML, CSS, and JS.
- Assistant
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Interactive Photo Gallery</title> <style> * { box-sizing: border-box; } body { margin: 0; padding: 2rem; background: linear-gradient(135deg, #667eea 0%, #764ba2 100%); font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; min-height: 100vh; color: #333; } h1 { text-align: center; color: white; margin-bottom: 3rem; font-size: 2.5rem; text-shadow: 0 2px 4px rgba(0,0,0,0.3); } .gallery { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 1.5rem; max-width: 1400px; margin: 0 auto; } .image-container { aspect-ratio: 4 / 3; overflow: hidden; border-radius: 16px; cursor: pointer; transition: all 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94); box-shadow: 0 8px 25px rgba(0, 0, 0, 0.15); position: relative; transform: scale(1); z-index: 1; } .image-container:hover { transform: scale(1.08); box-shadow: 0 15px 35px rgba(0, 0, 0, 0.25); } .image-container img { width: 100%; height: 100%; object-fit: cover; display: block; transition: transform 0.4s cubic-bezier(0.25, 0.46, 0.45, 0.94); } /* Enlarged state: larger scale, higher z-index, prominent shadow */ .image-container.enlarged { transform: scale(1.5) !important; z-index: 100; box-shadow: 0 30px 60px rgba(0, 0, 0, 0.4); } .image-container.enlarged:hover { transform: scale(1.55) !important; box-shadow: 0 35px 70px rgba(0, 0, 0, 0.45); } .image-container.enlarged img { transform: scale(1.02); /* Subtle inner zoom for enlarged state */ } /* Responsive adjustments */ @media (max-width: 768px) { .gallery { grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 1rem; padding: 0 1rem; } .image-container.enlarged { transform: scale(1.3) !important; /* Smaller scale on mobile to fit */ } h1 { font-size: 2rem; } } </style> </head> <body> <h1>Interactive Photo Gallery</h1> <div class="gallery" id="gallery"> <!-- Images will be dynamically added via JS for easier management --> </div> <script> // Array of image sources (using Picsum for random high-quality placeholders) const images = [ 'https://picsum.photos/500/400?random=1', 'https://picsum.photos/500/400?random=2', 'https://picsum.photos/500/400?random=3', 'https://picsum.photos/500/400?random=4', 'https://picsum.photos/500/400?random=5', 'https://picsum.photos/500/400?random=6', 'https://picsum.photos/500/400?random=7', 'https://picsum.photos/500/400?random=8', 'https://picsum.photos/500/400?random=9' ]; // Create gallery dynamically const gallery = document.getElementById('gallery'); images.forEach(src => { const container = document.createElement('div'); container.className = 'image-container'; const img = document.createElement('img'); img.src = src; img.alt = 'Gallery image'; container.appendChild(img); gallery.appendChild(container); }); // Add click event listeners for toggle enlarge/shrink document.querySelectorAll('.image-container').forEach(container => { container.addEventListener('click', (e) => { e.stopPropagation(); // Prevent any bubbling if needed container.classList.toggle('enlarged'); }); }); // Optional: Click outside to shrink all (enhances UX) document.addEventListener('click', (e) => { if (!e.target.closest('.image-container')) { document.querySelectorAll('.image-container.enlarged').forEach(cont => { cont.classList.remove('enlarged'); }); } }); </script> </body> </html>How it works:
- Smooth enlargement on hover: Every image container smoothly scales up to 1.08x (with enhanced shadow) on hover and returns smoothly on mouseout.
- Toggle on click: Click any image to enlarge it persistently to 1.5x (1.3x on mobile, with prominent shadow and high z-index so it layers on top). Click again on the same image to return it to original size.
- Smooth transitions: All using CSS
transitionwith cubic-bezier easing for natural feel. - Fully responsive: Grid adapts to screen size; enlarged scale adjusts on mobile.
- Bonus UX: Hover works even on enlarged images (slight additional scale). Click outside any image to shrink all enlarged ones.
- Performance: Uses efficient CSS transforms (hardware-accelerated). Dynamic image loading for cleanliness.
Copy-paste into an HTML file and open in a browser to interact! 🖼️✨
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.