I created a webpage with a theme of Image gallery. I have inserted several thumbnails. Now I want that whenever a user click on a thumbnail the image gets larger and is displayed in the bottom space of the page.
Here whenever I click on a thumbnail above, I want that the image is displayed in the encircled part of the page.
Below is my HTML and CSS code.
HTML –
<!DOCTYPE html>
<html>
<head style="color: antiquewhite;">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="image_gallery.css">
<title style="color: blue;">Image Gallery</title>
</head>
<body class="FullBody">
<div class="Heading">
Responsive Image Gallery
</div>
<div class = "AllImages">
<img src="1.jpg" alt="1st image">
<img src="2.jpg" alt="2nd image">
<img src="3.jpg" alt="3rd image">
<img src="4.jpeg" alt="4th image">
<img src="5.jpg" alt="5th image">
<img src="6.jpg" alt="6th image">
<img src="7.jpg" alt="7th image">
<img src="8.jpg" alt="8th image">
<img src="9.jpg" alt="9th image">
<img src="10.jpg" alt="10th image">
</div>
<footer class="Footer">
<span class="FooterRight">Copyright - Harsh Jain</span>
<span class="FooterLeft">Created - 03/07/2024</span>
</footer>
</body>
</html>
CSS –
.FullBody
{
background-image: url('BackgroundImage.jpg');
background-size: cover ;
}
.Heading
{
font-family: Impact, Haettenschweiler, 'Arial Narrow Bold', sans-serif;
font-size: xx-large;
align-content: center;
text-align: center;
color: azure;
height: 100px;
}
.Footer
{
height:40px;
background-color: black;
color: white;
align-content: center;
font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;
font-size: medium;
width:100%;
position: fixed;
bottom: 0px;
left:0px;
}
.FooterLeft
{
float: left;
}
.FooterRight
{
float: right;
}
img
{
height:100px;
width:9.78%;
border:2px solid whitesmoke;
border-radius: 2px;
float:left;
}
.AllImages
{
margin-left:10px;
margin-right:10px;
margin-top:2px;
margin-bottom: 2px;
}
I tried searching but got no help all I got was resizing of images on clicking.
One of the link is here.
2
Answers
You need to create a container that will handle the image preview, then create a js function that will show the selected image and apply the design.
I made a simple preview image below base on your code, so you can refer to it.
function displayImage(img) { var largeImage = document.getElementById("largeImage"); largeImage.src = img.src; }
In this setup:
The displayImage function is called whenever a thumbnail is clicked.
This function sets the src attribute of the large image to the src of the clicked thumbnail, displaying it in the displayArea.