diff options
| author | Eltrac <hi@guhub.cn> | 2025-09-15 14:27:06 +0800 |
|---|---|---|
| committer | Eltrac <hi@guhub.cn> | 2025-09-15 14:27:06 +0800 |
| commit | 5f62762097858b7ca074109ead5dd30290ad88cf (patch) | |
| tree | d7e07084793906a3b5377ac9edd88b666e97a045 /src/lightbox.js | |
| parent | 4f8bc303471f732eb8082a97fb5576914fac18e4 (diff) | |
feat: keyboard shortcuts
Diffstat (limited to 'src/lightbox.js')
| -rw-r--r-- | src/lightbox.js | 9 |
1 files changed, 9 insertions, 0 deletions
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; |
