<!DOCTYPE html>
<html lang="ko">
<head>
<meta name="viewport" content="width=device-width">
<meta charset="UTF-8">
<link rel="stylesheet" href="../reset.css">
<title>Image gallery with Overlay</title>
<style>
#gallery {
display: flex;
gap: 10px;
}
#gallery > li > a { display: block; }
#gallery > li > a > img {
display: block;
width: 200px;
border: 4px solid white;
box-shadow: 4px 4px 4px rgba(0, 0, 0, 0.4);
}
#overlay {
position: fixed;
top: 0; right: 0; bottom: 0; left: 0;
background-color: rgba(0, 0, 0, 0.8);
display: none;
}
#overlay > img {
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
border: 10px solid white;
max-width: 80%;
max-height: 80%;
}
</style>
<script>
window.addEventListener('load', function () {
const galleryItems = document.querySelectorAll('#gallery > li > a');
const overlay = document.getElementById('overlay');
const photo = overlay.firstElementChild;
for (let i = 0; i < galleryItems.length; i++) {
galleryItems[i].addEventListener('click', function(event) {
event.preventDefault();
photo.src = this.href;
overlay.style.display = 'block';
});
}
overlay.addEventListener('click', function() {
this.removeAttribute('style');
});
photo.addEventListener('click', function(event) {
event.stopPropagation();
});
});
</script>
</head>
<body>
<div id="overlay">
<img src="https://i.imgur.com/7Mu8BZg.png" alt="Photo" id="photo">
</div>
<ul id="gallery">
<li>
<a href="https://i.imgur.com/7Mu8BZg.png">
<img src="https://i.imgur.com/RDQGlFG.png" alt="Thumbnail">
</a>
</li>
<li>
<a href="https://i.imgur.com/kwD72gU.png">
<img src="https://i.imgur.com/VaVlu0Y.png" alt="Thumbnail">
</a>
</li>
<li>
<a href="https://i.imgur.com/qOU9yuQ.png">
<img src="https://i.imgur.com/AJkIaya.png" alt="Thumbnail">
</a>
</li>
<li>
<a href="https://i.imgur.com/YfsvbdE.png">
<img src="https://i.imgur.com/Y51UhBK.png" alt="Thumbnail">
</a>
</li>
<li>
<a href="https://i.imgur.com/3KWpPQv.png">
<img src="https://i.imgur.com/gbPCnTb.png" alt="Thumbnail">
</a>
</li>
</ul>
</body>
</html>
