People, good afternoon
I have a JS + CSS code to open an image at normal size through a reduced image. I was able to do this with a single image, however, when I put a loop in php, an error occurs.
Follow below:
<-- Aqui deveria começar o loop em php -->
<img id="myImg" src="imagem_grande.jpg">
<div id="myModal" class="modal">
<span class="close"><img src="imagem_close.png"></span>
<img src="imagem_grande.png" class="modal-content" width="100%"> <div id="caption"></div>
</div>
<-- Aqui deveria fechar o loop em php -->
<script>
// Get the modal
var modal = document.getElementById('myModal');
// Get the image and insert it inside the modal - use its "alt" text as a caption
var img = document.getElementById('myImg');
var modalImg = document.getElementById("img01");
var captionText = document.getElementById("caption");
img.onclick = function(){
modal.style.display = "block";
modalImg.src = this.src;
modalImg.alt = this.alt;
captionText.innerHTML = this.alt;
}
// Get the <span> element that closes the modal
var span = document.getElementsByClassName("close")[0];
// When the user clicks on <span> (x), close the modal
span.onclick = function() {
modal.style.display = "none";
}
</script>
I have no practice in JS.
Thanks for the help!
Abs!