From 0c107b21eda2051237f878c8bf794b03f81ff9f9 Mon Sep 17 00:00:00 2001 From: liabru Date: Sun, 4 May 2014 12:37:23 +0100 Subject: [PATCH] added mouse.wheelDelta --- src/core/Mouse.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/core/Mouse.js b/src/core/Mouse.js index 2f53c6f..f4182b6 100644 --- a/src/core/Mouse.js +++ b/src/core/Mouse.js @@ -22,12 +22,14 @@ var Mouse; this.mouseupPosition = { x: 0, y: 0 }; this.offset = { x: 0, y: 0 }; this.scale = { x: 1, y: 1 }; + this.wheelDelta = 0; this.button = -1; this.sourceEvents = { mousemove: null, mousedown: null, - mouseup: null + mouseup: null, + mousewheel: null }; this.mousemove = function(event) { @@ -84,6 +86,11 @@ var Mouse; 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); }; @@ -110,6 +117,9 @@ var Mouse; element.addEventListener('mousedown', mouse.mousedown); element.addEventListener('mouseup', mouse.mouseup); + element.addEventListener("mousewheel", mouse.mousewheel); + element.addEventListener("DOMMouseScroll", mouse.mousewheel); + element.addEventListener('touchmove', mouse.mousemove); element.addEventListener('touchstart', mouse.mousedown); element.addEventListener('touchend', mouse.mouseup); @@ -124,6 +134,8 @@ var Mouse; mouse.sourceEvents.mousemove = null; mouse.sourceEvents.mousedown = null; mouse.sourceEvents.mouseup = null; + mouse.sourceEvents.mousewheel = null; + mouse.wheelDelta = 0; }; /**