0
0
Fork 0
mirror of https://github.com/liabru/matter-js.git synced 2024-11-23 09:26:51 -05:00

added mouse.wheelDelta

This commit is contained in:
liabru 2014-05-04 12:37:23 +01:00
parent 8427e89938
commit 0c107b21ed

View file

@ -22,12 +22,14 @@ var Mouse;
this.mouseupPosition = { x: 0, y: 0 }; this.mouseupPosition = { x: 0, y: 0 };
this.offset = { x: 0, y: 0 }; this.offset = { x: 0, y: 0 };
this.scale = { x: 1, y: 1 }; this.scale = { x: 1, y: 1 };
this.wheelDelta = 0;
this.button = -1; this.button = -1;
this.sourceEvents = { this.sourceEvents = {
mousemove: null, mousemove: null,
mousedown: null, mousedown: null,
mouseup: null mouseup: null,
mousewheel: null
}; };
this.mousemove = function(event) { this.mousemove = function(event) {
@ -84,6 +86,11 @@ var Mouse;
mouse.sourceEvents.mouseup = event; mouse.sourceEvents.mouseup = event;
}; };
this.mousewheel = function(event) {
mouse.wheelDelta = Math.max(-1, Math.min(1, event.wheelDelta || -event.detail));
event.preventDefault();
};
Mouse.setElement(mouse, mouse.element); Mouse.setElement(mouse, mouse.element);
}; };
@ -110,6 +117,9 @@ var Mouse;
element.addEventListener('mousedown', mouse.mousedown); element.addEventListener('mousedown', mouse.mousedown);
element.addEventListener('mouseup', mouse.mouseup); element.addEventListener('mouseup', mouse.mouseup);
element.addEventListener("mousewheel", mouse.mousewheel);
element.addEventListener("DOMMouseScroll", mouse.mousewheel);
element.addEventListener('touchmove', mouse.mousemove); element.addEventListener('touchmove', mouse.mousemove);
element.addEventListener('touchstart', mouse.mousedown); element.addEventListener('touchstart', mouse.mousedown);
element.addEventListener('touchend', mouse.mouseup); element.addEventListener('touchend', mouse.mouseup);
@ -124,6 +134,8 @@ var Mouse;
mouse.sourceEvents.mousemove = null; mouse.sourceEvents.mousemove = null;
mouse.sourceEvents.mousedown = null; mouse.sourceEvents.mousedown = null;
mouse.sourceEvents.mouseup = null; mouse.sourceEvents.mouseup = null;
mouse.sourceEvents.mousewheel = null;
mouse.wheelDelta = 0;
}; };
/** /**