From 0249e947e4569c8bbc28521b8b00b158ddb55164 Mon Sep 17 00:00:00 2001 From: Thierry Marianne Date: Sun, 15 Sep 2013 10:27:01 +0200 Subject: [PATCH] Add mousewheel event listener --- shower.js | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/shower.js b/shower.js index 8c225e3..8f46732 100755 --- a/shower.js +++ b/shower.js @@ -774,6 +774,38 @@ window.shower = window.shower || (function(window, document, undefined) { return '#' + shower.slideList[slideNumber].id; }; + /** + * Wheel event listener + * @param e event + */ + shower.wheel = function (e) { + var body = document.querySelector('body'), + wheelDown, + lockedWheel = body.getAttribute('data-scroll') === 'locked'; + + if (!lockedWheel && !shower.isListMode()) { + body.setAttribute('data-scroll', 'locked'); + + if (e.deltaY === undefined) { + // Chrome, Opera, Safari + wheelDown = e.wheelDeltaY < 0; + } else { + // Firefox + wheelDown = e.deltaY > 0; + } + + if (wheelDown) { + shower._turnNextSlide(); + } else { + shower._turnPreviousSlide(); + } + + setTimeout(function () { + body.setAttribute('data-scroll', 'unlocked'); + }, 200); + } + } + // Event handlers window.addEventListener('DOMContentLoaded', function() { @@ -950,6 +982,10 @@ window.shower = window.shower || (function(window, document, undefined) { } }, false); + document.addEventListener('wheel', shower.wheel, false); + + document.addEventListener('mousewheel', shower.wheel, false); + return shower; })(this, this.document);