mouse-wheel
Advanced tools
Comparing version 1.0.1 to 1.0.2
{ | ||
"name": "mouse-wheel", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Consistent cross browser mouse wheel movement", | ||
@@ -5,0 +5,0 @@ "main": "wheel.js", |
20
wheel.js
'use strict' | ||
var toPX = require('to-px') | ||
var now = require('right-now') | ||
var sgn = require('signum') | ||
module.exports = mouseWheelListen | ||
function filter(cur, prev, dt) { | ||
return sgn(cur) * Math.sqrt(Math.abs(cur)) | ||
} | ||
function mouseWheelListen(element, callback, noScroll) { | ||
@@ -20,6 +14,2 @@ if(typeof element === 'function') { | ||
var lineHeight = toPX('ex', element) | ||
var lastT = now() | ||
var lastX = 0 | ||
var lastY = 0 | ||
var lastZ = 0 | ||
element.addEventListener('wheel', function(ev) { | ||
@@ -29,4 +19,2 @@ if(noScroll) { | ||
} | ||
var t = now() | ||
var dt = t - lastT | ||
var dx = ev.deltaX || 0 | ||
@@ -37,3 +25,2 @@ var dy = ev.deltaY || 0 | ||
var scale = 1 | ||
lastT = t | ||
switch(mode) { | ||
@@ -50,9 +37,2 @@ case 1: | ||
dz *= scale | ||
var cx = dx, cy = dy, cz = dz | ||
dx = filter(dx, lastX, dt) | ||
dy = filter(dy, lastY, dt) | ||
dz = filter(dz, lastZ, dt) | ||
lastX = cx | ||
lastY = cy | ||
lastZ = cz | ||
if(dx || dy || dz) { | ||
@@ -59,0 +39,0 @@ return callback(dx, dy, dz) |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
4317
56