From d385305f5e2be4d36238925639734f6dbc029559 Mon Sep 17 00:00:00 2001 From: Markus Pawlata Date: Tue, 30 Mar 2021 22:34:54 +0200 Subject: [PATCH] (feat) Add mousewheel support --- src/baguetteBox.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/baguetteBox.js b/src/baguetteBox.js index 71c642a8..0be7c4a5 100644 --- a/src/baguetteBox.js +++ b/src/baguetteBox.js @@ -47,6 +47,7 @@ animation: 'slideIn', afterShow: null, afterHide: null, + handleWheel: false, onChange: null, overlayBackgroundColor: 'rgba(0,0,0,.8)' }; @@ -78,6 +79,16 @@ hideOverlay(); } }; + var overlayWheelHandler = function(event) { + if (options.handleWheel === true) { + event.preventDefault ? event.preventDefault() : event.returnValue = false; // eslint-disable-line no-unused-expressions + if (event.deltaY > 0) { + showNextImage() + } else { + showPreviousImage(); + } + } + } var previousButtonClickHandler = function(event) { event.stopPropagation ? event.stopPropagation() : event.cancelBubble = true; // eslint-disable-line no-unused-expressions showPreviousImage(); @@ -321,6 +332,7 @@ var nonPassiveEvent = supports.passiveEvents ? { passive: true } : null; bind(overlay, 'click', overlayClickHandler); + bind(overlay, 'wheel', overlayWheelHandler); bind(previousButton, 'click', previousButtonClickHandler); bind(nextButton, 'click', nextButtonClickHandler); bind(closeButton, 'click', closeButtonClickHandler); @@ -336,6 +348,7 @@ var nonPassiveEvent = supports.passiveEvents ? { passive: true } : null; unbind(overlay, 'click', overlayClickHandler); + unbind(overlay, 'wheel', overlayWheelHandler); unbind(previousButton, 'click', previousButtonClickHandler); unbind(nextButton, 'click', nextButtonClickHandler); unbind(closeButton, 'click', closeButtonClickHandler);