From f57c548ffed02259c3ad9860ac261ad0a413f264 Mon Sep 17 00:00:00 2001 From: Lucas Kellner Date: Sat, 27 Apr 2019 22:43:20 -0400 Subject: [PATCH] add mouse wheel listener to numbercontrollerbox --- src/dat/controllers/NumberControllerBox.js | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/dat/controllers/NumberControllerBox.js b/src/dat/controllers/NumberControllerBox.js index 462ebf2..dbbc9fd 100644 --- a/src/dat/controllers/NumberControllerBox.js +++ b/src/dat/controllers/NumberControllerBox.js @@ -42,6 +42,8 @@ class NumberControllerBox extends NumberController { const _this = this; + const mousewheelevt = (/Firefox/i.test(navigator.userAgent)) ? 'DOMMouseScroll' : 'mousewheel'; + /** * {Number} Previous mouse y position * @ignore @@ -84,6 +86,12 @@ class NumberControllerBox extends NumberController { prevY = e.clientY; } + function onMouseWheel(e) { + e.preventDefault(); + const direction = ((e.deltaY || -e.wheelDelta || e.detail) >> 10) || 1; + _this.setValue(_this.getValue() + direction * _this.__impliedStep); + } + this.__input = document.createElement('input'); this.__input.setAttribute('type', 'text'); @@ -92,6 +100,7 @@ class NumberControllerBox extends NumberController { dom.bind(this.__input, 'change', onChange); dom.bind(this.__input, 'blur', onBlur); dom.bind(this.__input, 'mousedown', onMouseDown); + dom.bind(this.__input, mousewheelevt, onMouseWheel); dom.bind(this.__input, 'keydown', function(e) { // When pressing enter, you can be as precise as you want. if (e.keyCode === 13) {