jquery icon indicating copy to clipboard operation
jquery copied to clipboard

offset() can be inaccurate when pinch-zoomed

Open bokand opened this issue 8 years ago • 6 comments

Bug Reports:

  • What do you expect to happen? offset() should return offset from document origin
  • What actually happens? On some browsers, it can be off when pinch-zoomed
  • Which browsers are affected? Edge, possibly Safari in the future.

Description

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

http://jsbin.com/vucayumeta

bokand avatar Oct 19 '17 18:10 bokand

Thanks for opening an issue. This may need to be fixed by browsers, but we'll leave open for the time being in case anyone finds a workaround.

timmywil avatar Oct 30 '17 16:10 timmywil

The workaround is for offset() to diff the documentElement's getBoundingClientRect and the element's getBoundingClientRect if I recall correctly.

smfr avatar Nov 01 '17 19:11 smfr

Right, the offset for element E can be calculated as:

offset.y = E.getBoundingClientRect().y - document.documentElement.getBoundingClientRect().y

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?

bokand avatar Nov 02 '17 00:11 bokand

When fixing this, the fix might be able to incorporate #3479.

timmywil avatar Jan 22 '18 17:01 timmywil

@smfr or @bokand would either of you like to submit a PR? As far as the CSS offset/transform problem we already document that our dimensions are not accurate for those cases.

dmethvin avatar May 14 '18 18:05 dmethvin

I can do it but I won't have the time to do it in the next few weeks

bokand avatar May 17 '18 14:05 bokand