-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Toolbar audit incorrectly flagging images as above the fold #10891
Comments
The problem is with how the above/below the fold is detected. The following code:
does not work when the I've found two options to correctly determine the offsetTop.
or by adding
I'd be happy to submit a PR with either solution, although the latter seems cleaner and easier to understand. |
Hmm, won't the second solution cause a problem when you arrive on the page scrolled? |
Yes, you're right that Scroll down half the page on the StackBlitz, hit the StackBlitz refresh button, and have a look at the console output:
A few things we can observe:
|
…1617) * fix: audit incorrectly flagging images as above the fold (#10891) Previously used �lement.offsetTop to find the y position of the image, which does not work when the element parent has a position: relative property. Instead, this uses �lement.getBoundingClientRect().y top get real y position of the image. There's one issue though, which is that getBoundingClientRect returns the position relative to the user's viewport, not the absolute position. So, add window.scrollY to the value to cancel that effect out, and you have the element's absolute position. https://developer.mozilla.org/en-US/docs/Web/API/Element/getBoundingClientRect https://developer.mozilla.org/en-US/docs/Web/API/Window/scrollY * chore: add changeset
Astro Info
If this issue only occurs in one browser, which browser is a problem?
No response
Describe the Bug
The Toolbar Audit shows:
for images that are clearly NOT above the fold.
What's the expected result?
The Toolbar Audit should not show warnings for images that are not above the fold
Link to Minimal Reproducible Example
https://stackblitz.com/edit/github-ddfdpg?file=src%2Fpages%2Findex.astro
Participation
The text was updated successfully, but these errors were encountered: