From 267f332d95ce3d122542d38ded40b96775b9ee74 Mon Sep 17 00:00:00 2001 From: Camol Date: Sun, 30 Jan 2022 11:53:34 +0800 Subject: [PATCH] fix: disable mousewheel in modern browsers --- common/apiBase.js | 35 +++++++++++++++++++++++++++-------- 1 file changed, 27 insertions(+), 8 deletions(-) diff --git a/common/apiBase.js b/common/apiBase.js index 2e2246296e..dd338d04ff 100644 --- a/common/apiBase.js +++ b/common/apiBase.js @@ -284,14 +284,33 @@ }; // disable mousewheel on macOS - if (AscCommon.AscBrowser.isMacOs) - { - document.body.onmousewheel = function(e) { - if (e.stopPropagation) - e.stopPropagation(); - e.returnValue = false; - return false; - }; + if (AscCommon.AscBrowser.isMacOs) { + let passiveIfSupported = false; + try { + document.body.addEventListener('test', null, Object.defineProperty({}, "passive", { + get: function () { + passiveIfSupported = { + passive = false + } + } + })); + } catch (err) { } + if (document.body.addEventListener) { + document.body.addEventListener('mousewheel', function (e) { + if (e.stopPropagation) + e.stopPropagation(); + if (passiveIfSupported) { + e.preventDefault() + } + }, passiveIfSupported); + } else { + document.body.onmousewheel = function (e) { + if (e.stopPropagation) + e.stopPropagation(); + e.returnValue = false; + return false; + }; + } } }; baseEditorsApi.prototype._editorNameById = function()