[fix] Dimensions measurements with window zoom

Fixes `window.height` and `window.width` so that they do not change when
pinch-zoomed. This issue was introduced by #2438 when `documentElement`
measurements were replaced by `visualViewport`.

Close #2520
This commit is contained in:
Ali Toshmatov
2023-05-13 14:31:48 +05:00
committed by Nicolas Gallagher
parent 9b69c73938
commit 6ab9b6125b

View File

@@ -62,8 +62,14 @@ function update() {
*/
if (win.visualViewport) {
const visualViewport = win.visualViewport;
height = Math.round(visualViewport.height);
width = Math.round(visualViewport.width);
/**
* We are multiplying by scale because height and width from visual viewport
* also react to pinch zoom, and become smaller when zoomed. But it is not desired
* behaviour, since originally documentElement client height and width were used,
* and they do not react to pinch zoom.
*/
height = Math.round(visualViewport.height * visualViewport.scale);
width = Math.round(visualViewport.width * visualViewport.scale);
} else {
const docEl = win.document.documentElement;
height = docEl.clientHeight;