'use strict' var toPX = require('to-px') module.exports = mouseWheelListen function mouseWheelListen(element, callback, noScroll) { if(typeof element === 'function') { noScroll = !!callback callback = element element = window } var lineHeight = toPX('ex', element) var listener = function(ev) { if(noScroll) { ev.preventDefault() } var dx = ev.deltaX || 0 var dy = ev.deltaY || 0 var dz = ev.deltaZ || 0 var mode = ev.deltaMode var scale = 1 switch(mode) { case 1: scale = lineHeight break case 2: scale = window.innerHeight break } dx *= scale dy *= scale dz *= scale if(dx || dy || dz) { return callback(dx, dy, dz, ev) } } element.addEventListener('wheel', listener) return listener }