From 48f15efa690b95e5b0ae5154dc57caf8088ae2f5 Mon Sep 17 00:00:00 2001 From: Pierre Ossman Date: Tue, 16 Jun 2020 14:24:00 +0200 Subject: [PATCH] Compensate for visual viewport when moving cursor --- core/util/cursor.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/core/util/cursor.js b/core/util/cursor.js index 3f0b01bd..009bd6de 100644 --- a/core/util/cursor.js +++ b/core/util/cursor.js @@ -125,8 +125,16 @@ export default class Cursor { if (!useFallback) { return; } - this._position.x = clientX; - this._position.y = clientY; + // clientX/clientY are relative the _visual viewport_, + // but our position is relative the _layout viewport_, + // so try to compensate when we can + if (window.visualViewport) { + this._position.x = clientX + window.visualViewport.offsetLeft; + this._position.y = clientY + window.visualViewport.offsetTop; + } else { + this._position.x = clientX; + this._position.y = clientY; + } this._updatePosition(); let target = document.elementFromPoint(clientX, clientY); this._updateVisibility(target);