From 60dd64756eb6d5befdb112fa4a66e7833cd8d58c Mon Sep 17 00:00:00 2001 From: Eltrac Date: Mon, 15 Sep 2025 14:39:21 +0800 Subject: feat: close lightbox when scrolling --- src/lightbox.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'src/lightbox.js') diff --git a/src/lightbox.js b/src/lightbox.js index b8ef08c..0582149 100644 --- a/src/lightbox.js +++ b/src/lightbox.js @@ -14,7 +14,7 @@ export default class LightBox { this.container = container; this.initOverlay(); this.initImages(); - this.initKeyboardShortcuts(); + this.initControls(); } initOverlay() { @@ -37,12 +37,17 @@ export default class LightBox { }); } - initKeyboardShortcuts() { + initControls() { + // keyboard shortcuts document.addEventListener('keydown', e => { if (e.key === 'Escape' || e.key === ' ') { this.closeAll(); } }); + // scroll to dismiss + document.body.addEventListener('wheel', e => { + this.closeAll(); + }); } wrapInLink(image) { -- cgit v1.2.3