Skip to content

Commit 619fd18

Browse files
committed
MouseManager.preventDefaultWheel is a new boolean property, set via the inputMousePreventDefaultWheel config option that allows you to toggle capture of mouse wheel at runtime.
1 parent 2246b63 commit 619fd18

1 file changed

Lines changed: 25 additions & 1 deletion

File tree

src/input/mouse/MouseManager.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,16 @@ var MouseManager = new Class({
7272
*/
7373
this.preventDefaultMove = true;
7474

75+
/**
76+
* If `true` the DOM `wheel` event will have `preventDefault` set.
77+
*
78+
* @name Phaser.Input.Mouse.MouseManager#preventDefaultWheel
79+
* @type {boolean}
80+
* @default true
81+
* @since 3.50.0
82+
*/
83+
this.preventDefaultWheel = false;
84+
7585
/**
7686
* A boolean that controls if the Mouse Manager is enabled or not.
7787
* Can be toggled on the fly.
@@ -237,6 +247,7 @@ var MouseManager = new Class({
237247
this.preventDefaultDown = config.inputMousePreventDefaultDown;
238248
this.preventDefaultUp = config.inputMousePreventDefaultUp;
239249
this.preventDefaultMove = config.inputMousePreventDefaultMove;
250+
this.preventDefaultWheel = config.inputMousePreventDefaultWheel;
240251

241252
if (!this.target)
242253
{
@@ -437,6 +448,11 @@ var MouseManager = new Class({
437448
{
438449
manager.onMouseWheel(event);
439450
}
451+
452+
if (_this.preventDefaultWheel && event.target === canvas)
453+
{
454+
event.preventDefault();
455+
}
440456
};
441457

442458
var passive = { passive: true };
@@ -446,7 +462,15 @@ var MouseManager = new Class({
446462
target.addEventListener('mouseup', this.onMouseUp);
447463
target.addEventListener('mouseover', this.onMouseOver, passive);
448464
target.addEventListener('mouseout', this.onMouseOut, passive);
449-
target.addEventListener('wheel', this.onMouseWheel, passive);
465+
466+
if (this.preventDefaultWheel)
467+
{
468+
target.addEventListener('wheel', this.onMouseWheel, { passive: false });
469+
}
470+
else
471+
{
472+
target.addEventListener('wheel', this.onMouseWheel, passive);
473+
}
450474

451475
if (window && manager.game.config.inputWindowEvents)
452476
{

0 commit comments

Comments
 (0)