Latest Update:
For those using version 0.31.1 or higher, it is recommended to utilize webFrame.setZoomLevelLimits in the render process. This method proves effective for managing smart zoom on Mac, especially when dealing with document.addEventListener.
Here's an example:
require('electron').webFrame.setZoomLevelLimits(1, 1)
Earlier Update:
The deltaY
property for pinch zoom now returns a float
value, while normal scroll events still produce an int
value. This solution also addresses any issues related to the Ctrl key functionality.
Explore Demo 2.
document.addEventListener('mousewheel', function(e) {
if(e.deltaY % 1 !== 0) {
e.preventDefault();
}
});
Upon inspecting with Chromium's monitorEvents(document)
, I discovered that the event responsible for this behavior is mousewheel
. However, discerning the disparity between regular scrolling and pinch zoom remains a challenge.
During pinch zoom, the attribute e.ctrlKey = true
, whereas conventional scrolling events have e.ctrlKey = false
. It's worth noting that holding down the ctrl
key while scrolling will set e.ctrlKey
to true
.
Regrettably, a definitive solution continues to elude me. :(
Check out the working demo here: Demo
document.addEventListener('mousewheel', function(e) {
if(e.ctrlKey) {
e.preventDefault();
}
});