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

helpers\ImageLazifier: set placeholder src #1204

Merged
merged 4 commits into from
Jun 21, 2020
Merged

helpers\ImageLazifier: set placeholder src #1204

merged 4 commits into from
Jun 21, 2020

Conversation

jtojnar
Copy link
Member

@jtojnar jtojnar commented Jun 21, 2020

With lazy loading of images enabled, img tags did not have a src attribute, causing the browsers to render them as zero-height boxes. This made it impossible to determine the precise height of the article content, leading to articles sometimes being rendered in column view, even though they would not fit a single screen with images loaded.

In Firefox, it is possible to use broken non-image (e.g. about:blank page) and it will render a rectangle respecting the width and height ratio, there must be no alt attribute, though. And Chromium will not respect the aspect ratio either.

https://jsfiddle.net/jtojnar/yrdskx0n/5/

It is also possible to use a real image (e.g. 1×1 px dot) but then the height: auto in CSS causes the images to respect the size of the placeholder, not the specified dimensions. For that reason we need to use a placeholder of the same dimensions as the original image.

This will not help for images that do not specify dimensions but then again, we cannot know their dimension until they are loaded anyway, so let’s just fall back to 800×600 as a guess.

Closes: #1203

@jtojnar jtojnar force-pushed the lazyimg-dims branch 2 times, most recently from ceaf592 to 6fd4b63 Compare June 21, 2020 10:07
@jtojnar jtojnar added this to the 2.19 milestone Jun 21, 2020
So that they are easier to use.
Entries set width to 100% and add a padding. Since web browsers use content-box sizing by default, it was overflowing the page.
With lazy loading of images enabled, `img` tags did not have a `src` attribute, causing the browsers to render them as zero-height boxes. This made it impossible to determine the precise height of the article content, leading to articles sometimes being rendered in column view, even though they would not fit a single screen with images loaded.

In Firefox, it is possible to use broken non-image (e.g. about:blank page) and it will render a rectangle respecting the width and height ratio, there must be no alt attribute, though. And Chromium will not respect the aspect ratio either.

https://jsfiddle.net/jtojnar/yrdskx0n/5/

It is also possible to use a real image (e.g. 1×1 px dot) but then the `height: auto` in CSS causes the images to respect the size of the placeholder, not the specified dimensions. For that reason we need to use a placeholder of the same dimensions as the original image.

This will not help for images that do not specify dimensions but then again, we cannot know their dimension until they are loaded anyway, so let’s just fall back to 800×600 as a guess.
Use `data-selfoss-src` attribute instead of the invalid `ref` attribute.
@jtojnar jtojnar merged commit b77a7f7 into master Jun 21, 2020
@jtojnar jtojnar deleted the lazyimg-dims branch June 21, 2020 19:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Images not considered in article length
1 participant