use mousewheel to change a focused input[type=range]
This commit is contained in:
parent
dc4819e7d0
commit
30b9378d2c
11
js/dom.js
11
js/dom.js
|
@ -97,10 +97,13 @@ document.on('wheel', event => {
|
|||
if (!el || el !== event.target && !el.contains(event.target)) {
|
||||
return;
|
||||
}
|
||||
if (el.tagName === 'SELECT') {
|
||||
const old = el.selectedIndex;
|
||||
el.selectedIndex = Math.max(0, Math.min(el.length - 1, old + Math.sign(event.deltaY)));
|
||||
if (el.selectedIndex !== old) {
|
||||
const isSelect = el.tagName === 'SELECT';
|
||||
if (isSelect || el.tagName === 'INPUT' && el.type === 'range') {
|
||||
const key = isSelect ? 'selectedIndex' : 'valueAsNumber';
|
||||
const old = el[key];
|
||||
const rawVal = old + Math.sign(event.deltaY) * (el.step || 1);
|
||||
el[key] = Math.max(el.min || 0, Math.min(el.max || el.length - 1, rawVal));
|
||||
if (el[key] !== old) {
|
||||
el.dispatchEvent(new Event('change', {bubbles: true}));
|
||||
}
|
||||
event.preventDefault();
|
||||
|
|
Loading…
Reference in New Issue
Block a user