JSFiddle - React, Tailwind, and code Playground
by von
HTML
<main>
<div class="gallery">
<figure>
<span class="image-span">
<img src="https://source.unsplash.com/random/1920x1080" alt="Landscape" class="image">
</span>
<figcation>Landscape</figcation>
</figure>
</div>
<div class="mid-div"></div>
<div class="modal hide">
<div class="modal-box">
<span class="close">×</span>
<img src="" alt="" class="modal-image">
</div>
</div>
<style>
html {
scroll-behavior: smooth;
}
main *,
main *::after,
main *::before {
margin: 0;
padding: 0;
box-sizing: border-box;
}
.gallery {
display: flex;
}
figure {
width: 100px;
cursor: pointer;
}
figure .image {
width: 100px;
height: 100px;
object-fit: cover;
display: block;
pointer-events: none;
}
.image-span {
position: relative;
display: block;
pointer-events: none;
}
.image-span::after {
content: "";
display: block;
position: absolute;
top: 0;
left: 0;
bottom: 0;
right: 0;
width: 100%;
height: 100%;
background-image: url("mag-icon.png");
background-position: 100% 100%;
background-size: 75%;
background-repeat: no-repeat;
pointer-events: none;
}
figure figcaption {
text-align: center;
pointer-events: none;
}
.mid-div {
position: absolute;
top: 50%;
}
.modal {
display: flex;
justify-content: center;
align-items: center;
position: fixed;
top: 0;
bottom: 0;
left: 0;
right: 0;
background-color: rgba(0, 0, 0, 0.3);
z-index: 1;
}
.modal.hide {
display: none;
}
.modal-box {
max-width: 80%;
max-height: 80%;
background-color: wheat;
position: relative;
}
.modal-image {
width: 100%;
height: 100%;
object-fit: contain;
}
.close {
position: absolute;
top: 5px;
right: 5px;
color: white;
text-shadow: 0 0 0 dimgray;
cursor: pointer;
}
.close:hover {
color: dimgray;
text-shadow: 0 0 0 white;
}
</style>
<script>
const imgs = document.querySelectorAll("figure");
const modal = document.querySelector(".modal");
const modalImage = document.querySelector(".modal-image");
const close = document.querySelector(".close");
const midDiv = document.querySelector(".mid-div");
const closeModal = function ()...