Skip to content

Commit

Permalink
Close lightbox on 'scroll' and 'wheel' events
Browse files Browse the repository at this point in the history
  • Loading branch information
davidmz committed Jan 14, 2024
1 parent ef6d23c commit b6721fa
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions src/services/lightbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,19 @@ function initLightbox() {
lightbox.on('close', () => fsApi.isFullscreen() && fsApi.exit());
});

lightbox.on('bindEvents', () => {
const h = (e) => {
e.preventDefault();
lightbox.pswp.close();
};
window.addEventListener('scroll', h, { passive: false });
document.addEventListener('wheel', h, { passive: false });
lightbox.on('destroy', () => {
window.removeEventListener('scroll', h, { passive: false });
document.removeEventListener('wheel', h, { passive: false });
});
});

// Add filters for the correct open/close animation
lightbox.addFilter('placeholderSrc', (placeholderSrc, content) => {
const thumb = document.getElementById(content.data.pid);
Expand Down

0 comments on commit b6721fa

Please sign in to comment.