I'm currently in the process of creating a website with a gallery.
I want to have three images on which you can click, and three different galleries appear. For example, you click on the first picture and then a gallery will appear.
I have tried it with the help of the overlay element, but the problem is now no matter which image I click, the same gallery appears.
function on() {
document.getElementById("overlay").style.display = "block";
}
function off() {
document.getElementById("overlay").style.display = "none";
}
function myFunction(imgs) {
var expandImg = document.getElementById("expandedImg");
var imgText = document.getElementById("imgtext");
expandImg.src = imgs.src;
imgText.innerHTML = imgs.alt;
expandImg.parentElement.style.display = "block";
}
<div class="Galerie">
<div class="column">
<div style="padding:10px">
<img src="img/A1.jpg" onclick="on()" alt="Snow" style="width: 100%;">
</div>
</div>
<div class="column">
<div style="padding:10px">
<img src="img/B3.jpg" onclick="on()" alt="Forest" style="width:100%">
</div>
</div>
<div class="column">
<div style="padding:10px">
<img src="img/C1.JPG" onclick="on()" alt="Mountains" style="width:100%">
</div>
</div>
</div>
<div id="overlay" ondblclick="off()">
<div id="text" img data-src="">
<!-- The four columns -->
<div class="row">
<div class="Reiheeins">
<img src="img/A1.jpg" alt="Nature" style="width:100%" onclick="myFunction(this);">
</div>
<div class="Reiheeins">
<img src="img/A2.jpg" alt="Snow" style="width:100%" onclick="myFunction(this);">
</div>
<div class="Reiheeins">
<img src="img/A3.jpg" alt="Mountains" style="width:100%" onclick="myFunction(this);">
</div>
<div class="Reiheeins">
<img src="img/A4.jpg" alt="Lights" style="width:100%" onclick="myFunction(this);">
</div>
</div>
<div class="container">
<span onclick="this.parentElement.style.display='none'" class="closebtn">×</span>
<img id="expandedImg" style="width:100%">
<div id="imgtext"></div>
</div>
</div>
</div>
<div id="overlay" ondblclick="off()">
<div id="text" img data-src="">
<!-- The four columns -->
<div class="row1">
<div class="Reihezwei">
<img src="img/B3.jpg" alt="Nature" style="width:100%" onclick="myFunction(this);">
</div>
<div class="Reihezwei">
<img src="img/B4.jpg" alt="Snow" style="width:100%" onclick="myFunction(this);">
</div>
<div class="Reihezwei">
<img src="img/B6.jpg" alt="Mountains" style="width:100%" onclick="myFunction(this);">
</div>
<div class="Reihezwei">
<img src="img/B2.jpg" alt="Lights" style="width:100%" onclick="myFunction(this);">
</div>
</div>
<div class="container">
<span onclick="this.parentElement.style.display='none'" class="closebtn">×</span>
<img id="expandedImg" style="width:100%">
<div id="imgtext"></div>
</div>
Use data attributes and eventListeners
Here is an example that will show on click and hide when clicking the X