Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add visual viewport API demo #279

Merged
merged 3 commits into from
Aug 26, 2024
Merged

Conversation

chrisdavidmills
Copy link
Contributor

In mdn/content#34427, I have added documentation for the Visual Viewport API scrollend event, and a better demo to accompany this and related events.

This PR adds the full demo to the dom-examples repo. Once this is merged, I will update the content PR to point to this instead of the glitch page it currently points to.

@chrisdavidmills chrisdavidmills requested a review from a team as a code owner August 3, 2024 12:05
@chrisdavidmills chrisdavidmills requested review from dipikabh and removed request for a team August 3, 2024 12:05
@wbamberg
Copy link
Contributor

I think this example has too much accidental complexity - that is, things I have to understand, that aren't part of the API being demonstrated. AIUI the basic point of the demo is to:

  • keep the position of the "Total" box in the same place as we zoom
  • indicate in-progress zoom and finished zoom by changing the background color.

But most of the actual code isn't this, it's logic around figuring out which boxes are visible, and that doesn't seem particularly relevant to the API. It also seems to be buggy:

Screen Shot 2024-08-23 at 4 56 03 PM

...why is this showing me zero?

@chrisdavidmills
Copy link
Contributor Author

chrisdavidmills commented Aug 26, 2024

@wbamberg OK, the code is now vastly simpler; left me know what you think. I'm reporting the visualViewport offsetTop and offsetLeft values, and the window scrollX and scrollY values with each scroll, resize and scrollend event fire, to show the difference in what happens when you scroll on desktop versus mobile.

The behavior is still a bit odd sometimes on mobile. The visual viewport position generally changes as expected, but sometimes the window scrolls in addition to that, or instead of it.

I'll update the code in the docs now as well.

@bsmth bsmth requested a review from wbamberg August 26, 2024 11:32
Copy link
Contributor

@wbamberg wbamberg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 thank you Chris, much better IMO!

@wbamberg wbamberg merged commit aa3dd78 into mdn:main Aug 26, 2024
3 checks passed
@chrisdavidmills chrisdavidmills deleted the visual-viewport-api branch August 27, 2024 09:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants