Merge pull request #149 from thierrymarianne/mousewheel-event-listener
Add mousewheel event listener
This commit is contained in:
commit
01b70c4e42
36
shower.js
36
shower.js
|
@ -769,6 +769,38 @@ window.shower = window.shower || (function(window, document, undefined) {
|
||||||
return '#' + shower.slideList[slideNumber].id;
|
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
|
// Event handlers
|
||||||
|
|
||||||
window.addEventListener('DOMContentLoaded', function() {
|
window.addEventListener('DOMContentLoaded', function() {
|
||||||
|
@ -949,6 +981,10 @@ window.shower = window.shower || (function(window, document, undefined) {
|
||||||
}
|
}
|
||||||
}, false);
|
}, false);
|
||||||
|
|
||||||
|
document.addEventListener('wheel', shower.wheel, false);
|
||||||
|
|
||||||
|
document.addEventListener('mousewheel', shower.wheel, false);
|
||||||
|
|
||||||
return shower;
|
return shower;
|
||||||
|
|
||||||
})(this, this.document);
|
})(this, this.document);
|
||||||
|
|
Loading…
Reference in New Issue