jquery / jquery/jquery

offset() can be inaccurate when pinch-zoomed

Open
#3,822 6 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

help wanted Offset
Dominant language
JavaScript
Stars
59.8k
Forks
20.4k
Avg merge
17h 32m
Merged PRs (30d)
4

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the offset() implementation and reproduce the behavior using the linked JSBin test case in Edge with pinch-zoom enabled. Read the linked WebKit bug and Visual Viewport API background first. Done means offset() consistently returns the same document-origin offset after zooming and scrolling in the affected browsers.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
frontend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.