From 5f62762097858b7ca074109ead5dd30290ad88cf Mon Sep 17 00:00:00 2001 From: Eltrac Date: Mon, 15 Sep 2025 14:27:06 +0800 Subject: feat: keyboard shortcuts --- src/lightbox.js | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'src') diff --git a/src/lightbox.js b/src/lightbox.js index 36eccb8..2c2696c 100644 --- a/src/lightbox.js +++ b/src/lightbox.js @@ -14,6 +14,7 @@ export default class LightBox { this.container = container; this.initOverlay(); this.initImages(); + this.initKeyboardShortcuts(); } initOverlay() { @@ -36,6 +37,14 @@ export default class LightBox { }); } + initKeyboardShortcuts() { + document.addEventListener('keydown', e => { + if (e.key === 'Escape' || e.key === ' ') { + this.closeAll(); + } + }); + } + wrapInLink(image) { // wrap image with a link if it's not already wrapped const parent = image.parentElement; -- cgit v1.2.3