adding script to close overlay with esc

This commit is contained in:
hugogogo
2026-11-19 18:31:48 +01:00
parent 58981fe7e8
commit 62b6b1f223
+16
View File
@@ -471,3 +471,19 @@
</div> </div>
</div> </div>
</section> </section>
<!-- optional js : pressing Escape closes the lightbox by clicking the same
close link as the button. a real fragment navigation is required:
history.pushState() alone changes the url but does NOT update :target,
so the pure-css overlay would stay open. to disable, wrap the <script>
block below in an html comment again -->
<script>
document.addEventListener("keydown", function (event) {
if (
event.key === "Escape" &&
document.querySelector(".lightbox_list :target")
) {
document.querySelector(".lightbox_close").click();
}
});
</script>