Image Gallery with Lightbox
Grid gallery with lightbox modal
Preview
{ window.Prism.highlightElement($refs.codeEl) }) }"
class="w-full flex items-center justify-between px-6 py-4 text-left bg-gray-50 dark:bg-gray-900 hover:bg-gray-100 dark:hover:bg-gray-800 transition-colors cursor-pointer">
View Code
<div x-data="{ lightbox: false, currentImage: '', images: ['https://picsum.photos/400/300?random=1', 'https://picsum.photos/400/300?random=2', 'https://picsum.photos/400/300?random=3', 'https://picsum.photos/400/300?random=4'] }">
<div class="grid grid-cols-2 md:grid-cols-4 gap-4">
<template x-for="(image, index) in images" :key="index">
<img :src="image" @click="lightbox = true; currentImage = image" class="w-full h-32 object-cover rounded-lg cursor-pointer hover:opacity-75 transition">
</template>
</div>
<div x-show="lightbox" @click.self="lightbox = false" class="fixed inset-0 bg-black bg-opacity-90 flex items-center justify-center z-50" x-cloak>
<button @click="lightbox = false" class="absolute top-4 right-4 text-white text-3xl">×</button>
<img :src="currentImage" class="max-w-4xl max-h-screen">
</div>
</div>