mirror of
https://github.com/discourse/discourse.git
synced 2025-04-28 13:04:35 +08:00
UX: Remove background image after image has loaded (#13642)
* UX: Remove background image after image has loaded If an image has a `smallUpload`, that may be set as the `background-image` on the `img` element, and the `img` element set to use `lazy` loading. When the browser decides to load the `src` of the image element, it is rendered on top of the existing background image. However, if the image proper has a transparent background, the background image may be partially visible through the transparent portions of the image. This change creates an `onload` event that removes the background image when the image proper has completed loading.
This commit is contained in:
parent
17497600cd
commit
cf63931b9e
@ -15,8 +15,16 @@ export function nativeLazyLoading(api) {
|
|||||||
forEachImage(post, (img) => {
|
forEachImage(post, (img) => {
|
||||||
img.loading = "lazy";
|
img.loading = "lazy";
|
||||||
if (img.dataset.smallUpload) {
|
if (img.dataset.smallUpload) {
|
||||||
|
if (!img.complete) {
|
||||||
|
if (!img.onload) {
|
||||||
|
img.onload = () => {
|
||||||
|
img.removeAttribute("style");
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
img.style = `background-image: url(${img.dataset.smallUpload}); background-size: cover;`;
|
img.style = `background-image: url(${img.dataset.smallUpload}); background-size: cover;`;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}),
|
}),
|
||||||
{
|
{
|
||||||
onlyStream: true,
|
onlyStream: true,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user