I have a magazine in which each article shows several images. They are immortalized and made. I am not sure what their identifiers are. I recently added a code showing modal images, however the code has only one identifier, and therefore only the first image is displayed as a modal image. The rest are not displayed.
Please see the JavaScript and html code. Let me know how to change it. Thanks
JS code
var modal = document.getElementById('myModal');
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;
captionText.innerHTML = this.alt;
}
var span = document.getElementsByClassName("close")[0];
span.onclick = function() {
modal.style.display = "none";
}
HTML code
<div class="imagewrap">
{** check if link is from galley attachments*}
{if strpos($secCont->getLink(), "/") == false}
{foreach from=$imageUrlArray key=fileName item=urlLink}
{if $fileName == $secCont->getLink()}
<img src="{$urlLink}" id="myImg" alt="{$secCont->getLabel()}" width="300" height="200">
<div id="myModal" class="modal">
<span class="close" onclick="document.getElementById('myModal').style.display='none'">×</span>
<img class="modal-content" id="img01">
<div id="caption"></div>
</div>
<a style="font:4;"><a class="imagewrap" href="{$urlLink}"><strong>[Download figure]</strong></a>
{/if}
{/foreach}
{else}
<img src="{$secCont->getLink()}">
<a style="font:4;"><a class="imagewrap" href="{$secCont->getLink()}"><strong>[Download figure]</strong></a>
{/if}
</div>
source
share