Skip to content

Commit 56b5b09

Browse files
authored
Merge pull request #454 from zihanKuang/improve-lightbox-image-and-size
Improve Lightbox: Escape key support & Image size optimization
2 parents 7f186fb + dfd475c commit 56b5b09

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

layouts/_default/_markup/render-image.html

+2-1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,6 @@
88
<!-- attribution appreciated. github: zjeaton web: https://froglegs.co -->
99

1010
<div class="md__image">
11-
<img id="{{ first 6 (shuffle (seq 1 500)) }}" src="{{ .Destination | safeURL }}" onclick="openModal(this.id)" alt="{{ .Text }}" {{ with .Title}} class="{{ . }}" {{ end }} />
11+
<img id="{{ first 6 (shuffle (seq 1 500)) }}" src="{{ .Destination | safeURL }}" onclick="openModal(this.id)" alt="{{ .Text }}" {{ with .Title}} class="{{ . }}" {{ end }}
12+
style="max-width: 70%; max-height: 80vh; height: auto; display: block; margin: 0 auto; object-fit: contain;" />
1213
</div>

layouts/partials/image-modal.html

+7
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@
3434
document.getElementById("myModal").style.display = "none";
3535
}
3636

37+
// Listen for the Escape key to close the modal
38+
document.addEventListener("keydown", function (event) {
39+
if (event.key === "Escape") {
40+
closeModal();
41+
}
42+
});
43+
3744
</script>
3845

3946
<!-- To attach onclick attribute to all <img> -->

0 commit comments

Comments
 (0)