<!doctype html>
<
html
>
<
head
>
<
meta
charset
=
"UTF-8"
>
<
meta
name
=
"viewport"
content
=
"width=device-width, initial-scale=1.0"
>
<
meta
http-equiv
=
"X-UA-Compatible"
content
=
"ie=edge"
>
<
title
>Geeksforgeeks Image Gallery</
title
>
</
head
>
<
body
>
<
h1
class
=
"mt-10 mb-5 text-center text-3xl text-green-600"
>
Geeksforgeeks Image Gallery
</
h1
>
<
h3
class
=
"mb-10 text-center text-xl text-green-600"
>
Click the image to view
</
h3
>
<
div
class
=
"p-10 grid grid-cols-3 gap-5 "
>
<
img
class
=
"w-full h-full object-cover cursor-pointer"
src
=
alt
=
"Img 1"
id
=
"img1"
/>
<
img
class
=
"w-full h-full object-cover cursor-pointer"
src
=
alt
=
"Img 2"
id
=
"img2"
/>
<
img
class
=
"w-full h-full object-cover cursor-pointer"
src
=
alt
=
"Img 3"
id
=
"img3"
/>
</
div
>
<
div
id
=
"modal"
class="hidden fixed top-0 left-0 z-80
w-screen h-screen bg-black/70 flex
justify-center items-center">
<
a
class="fixed z-90 top-6 right-8
text-white text-5xl font-bold"
href
=
"javascript:void(0)"
onclick
=
"closeModal()"
>
×
</
a
>
<
img
id
=
"modal-img"
class
=
"max-w-[800px] max-h-[600px] object-cover"
/>
</
div
>
<
script
>
// Get all the img elements in the grid
var images = document.querySelectorAll('.grid img');
// Loop through each img element
images.forEach(function (img) {
// Add a click event listener to each img element
img.addEventListener('click', function () {
showModal(img.src);
});
});
// Get the modal by id
var modal = document.getElementById("modal");
// Get the modal image tag
var modalImg = document.getElementById("modal-img");
// This function is called when a small image is clicked
function showModal(src) {
modal.classList.remove('hidden');
modalImg.src = src;
}
// This function is called when the close button is clicked
function closeModal() {
modal.classList.add('hidden');
}
</
script
>
</
body
>
</
html
>