I have found this code, working and quite fitting with my aims. But I would fix the movement toward the bottom: it is not necessary, nor nice to go “to the hell” (I mean below the screen). It could be enough a narrower movement.
This the code:
It seems like your code, but after changing background-color:rgba(0,0,0,0.2); to background-color:rgba(0,0,0,0.4); my code works better avoiding a too dark whole screen.
But (in both cases) I can’t get the vertical center
You haven’t applied the flex rules to the modal as I mentioned. You applied the rules to the modal content which is wrong and then still left the transforms in place!
The code in my codepen is all you need but you will need to change the toggle of the js to say display:flex and not display:block or you break it all once again.
Here’s a very rough codepen using your code although you really should avoid inline event handlers and move them to the js instead but that’s a question for the js forum.
I hard coded the full image source in my demo but you are grabbing the image source from the thumbnail so you need to revert to that method of supplying the image.
Thank you. I will try later with my website, but in a single file I see that the zoom effect (that I prefer) would be quite ugly because of the opacity of the “growing” frame.
Very nice, thank you!
I need some further attempts today to adapt it to my website.
EDIT
I noticed (only now: stupid me) that you have changed the html of my code: no contanier1 div and (therefore, I guess) two different images (the small one and the big one). I will see if it is possible to use the same image (as in the original code).
EDIT
I have to do some other attempts, but the following code, so far, seems work:
function onClick(element) {
document.getElementById("modalimg").src = element.src;
document.getElementById("modaldiv").style.display = "flex";
}
html
not changed from my original, that is
<ul>
<li class="container1">
<img src="giotto_celano.jpg" alt="la morte del cavaliere da Celano"
onclick="onClick(this)" class="modal-hover-opacity" /> La morte del cavaliere da Celano
</li>
</ul>
<div id="modaldiv" class="modal" onclick="this.style.display='none'">
<span class="close">× </span>
<div class="modal-content">
<img id="modalimg" style="max-width:100%" />
</div>
Yes, it works. I’m doing some further improvements (simplifying my code, thank to your help).
I.g. i have removed close button, or the container1 div. And I noticed that is possible avoid even to set a modal-hover-opacity class, with the following code