Skip to content

Commit f8c1f5d

Browse files
author
Dmitrii Tarasov
committed
add modal on click
1 parent f9f1063 commit f8c1f5d

2 files changed

Lines changed: 77 additions & 2 deletions

File tree

project/index.html

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,46 @@ <h2 class="title">BibTeX</h2>
332332

333333
<!-- End of Statcounter Code -->
334334

335+
<!-- Add modal HTML structure -->
336+
<div id="imageModal" class="modal">
337+
<span class="modal-close">&times;</span>
338+
<img class="modal-content" id="modalImage">
339+
</div>
340+
341+
<script>
342+
// Get the modal
343+
const modal = document.getElementById("imageModal");
344+
const modalImg = document.getElementById("modalImage");
345+
const closeBtn = document.getElementsByClassName("modal-close")[0];
346+
347+
// Add click event to all images
348+
document.querySelectorAll('.image.is-16by9 img').forEach(img => {
349+
img.onclick = function() {
350+
modal.style.display = "block";
351+
modalImg.src = this.src;
352+
}
353+
});
354+
355+
// Close modal when clicking the close button
356+
closeBtn.onclick = function() {
357+
modal.style.display = "none";
358+
}
359+
360+
// Close modal when clicking outside the image
361+
window.onclick = function(event) {
362+
if (event.target == modal) {
363+
modal.style.display = "none";
364+
}
365+
}
366+
367+
// Close modal with Escape key
368+
document.addEventListener('keydown', function(event) {
369+
if (event.key === "Escape") {
370+
modal.style.display = "none";
371+
}
372+
});
373+
</script>
374+
335375
</body>
336376

337377
</html>

project/static/css/index.css

Lines changed: 37 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,6 @@ body {
161161
padding-top: 56.25%;
162162
position: relative;
163163
overflow: hidden;
164-
border-radius: 8px;
165-
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
166164
}
167165

168166
.image.is-16by9 img {
@@ -172,6 +170,12 @@ body {
172170
width: 100%;
173171
height: 100%;
174172
object-fit: contain;
173+
cursor: pointer;
174+
transition: opacity 0.3s ease;
175+
}
176+
177+
.image.is-16by9 img:hover {
178+
opacity: 0.9;
175179
}
176180

177181
.mb-6 {
@@ -197,5 +201,36 @@ body {
197201
}
198202
}
199203

204+
/* Modal styles */
205+
.modal {
206+
display: none;
207+
position: fixed;
208+
z-index: 1000;
209+
left: 0;
210+
top: 0;
211+
width: 100%;
212+
height: 100%;
213+
background-color: rgba(0, 0, 0, 0.9);
214+
overflow: auto;
215+
}
216+
217+
.modal-content {
218+
margin: auto;
219+
display: block;
220+
max-width: 90%;
221+
max-height: 90vh;
222+
object-fit: contain;
223+
}
224+
225+
.modal-close {
226+
position: absolute;
227+
top: 15px;
228+
right: 35px;
229+
color: #f1f1f1;
230+
font-size: 40px;
231+
font-weight: bold;
232+
cursor: pointer;
233+
}
234+
200235

201236

0 commit comments

Comments
 (0)