-
Notifications
You must be signed in to change notification settings - Fork 0
/
mousewheelinput.js
58 lines (50 loc) · 1.41 KB
/
mousewheelinput.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
var mousewheel_delta=0;
var mousewheel_timer=0;
var mousewheel_tick_interval=0;
function mousewheel_inactive(){
mousewheel_timer=mousewheel_delta=0;
}
function mousewheel_tick(obj){
if(mousewheel_timer==0){
clearInterval(mousewheel_tick_interval);
mousewheel_tick_interval=0;
}else{
if(mousewheel_delta>0) mousewheel_control_down.call(obj);
else mousewheel_control_up.call(obj);
}
}
function mousewheel_control_up(){
if(this.nodeName=='SELECT'){
if(this.selectedIndex<(this.options.length-1)){
this.selectedIndex++;
}
}else{
this.stepUp();
}
}
function mousewheel_control_down(){
if(this.nodeName=='SELECT'){
if(this.selectedIndex>0){
this.selectedIndex--;
}
}else{
this.stepDown();
}
}
function mousewheel_active(e){
clearTimeout(mousewheel_timer);
if(mousewheel_tick_interval==0){
mousewheel_tick();
mousewheel_tick_interval=setInterval(mousewheel_tick,100,this);
}
mousewheel_delta=Math.abs(e.deltaY)>Math.abs(e.deltaX)?e.deltaY:e.deltaX;
mousewheel_timer=setTimeout(mousewheel_inactive,100);
}
window.addEventListener('load',function(){
var all=document.querySelectorAll(
'select,input[type="number"],input[type="range"]'
);
for(var i=0;i<all.length;i++){
all[i].addEventListener('mousewheel',mousewheel_active);
}
});