Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
offset() can be inaccurate when pinch-zoomed #3822
Open the console and click/tap on the input box. Now pinch-zoom into the page, scroll to the very top, then scroll back down to the input box and tap it. The output should always be the same.
See https://bugs.webkit.org/show_bug.cgi?id=170981 for some background and https://developers.google.com/web/updates/2017/09/visual-viewport-api for the details.
The issue is that offset() is adding getBoundingClientRect (which is relative to the layout viewport) to window.pageX|YOffset which is relative to the visual viewport.
Note: Chrome recently made pageYOffset relative to the layout viewport so this isn't an issue there.
Link to test case
Right, the offset for element E can be calculated as:
But it has a (maybe a bit of esoteric) edge-case. If the page adds an offset or transform on the documentElement the result will be relative to the transformed documentElement, rather than the scroll origin - which differs from the current semantics. But maybe that's ok?