diff options
Diffstat (limited to 'src')
| -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; |
