Compensate for visual viewport when moving cursor

This commit is contained in:
Pierre Ossman 2020-06-16 14:24:00 +02:00
parent bb09e766ba
commit 48f15efa69
1 changed files with 10 additions and 2 deletions

View File

@ -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);