summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorEltrac <hi@guhub.cn>2025-09-15 14:39:21 +0800
committerEltrac <hi@guhub.cn>2025-09-15 14:39:21 +0800
commit60dd64756eb6d5befdb112fa4a66e7833cd8d58c (patch)
tree732c5a775df3135f1de26cbf134e1b68ff4c4b2d /src
parente6e67c809c073ef104e6a95a3400b462d720d795 (diff)
feat: close lightbox when scrolling
Diffstat (limited to 'src')
-rw-r--r--src/lightbox.js9
1 files changed, 7 insertions, 2 deletions
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) {