Skip to content
This repository has been archived by the owner on Mar 9, 2023. It is now read-only.

Commit

Permalink
feat: have a smooth transition (ANY-618)
Browse files Browse the repository at this point in the history
  • Loading branch information
jehon committed Oct 19, 2022
1 parent 7f9001c commit 7444659
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion jehon-image-loading.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ export default class JehonImageLoading extends HTMLElement {
opacity: 1;
transition: opacity ${JehonImageLoading.#transitionTimeMs}ms linear;
}
img[legacy] {
opacity: 0;
/* Removing the image is done a bit later to avoid the 'black' passage */
transition-delay: ${JehonImageLoading.#transitionTimeMs / 2}ms
}
img[loading] {
opacity: 0;
Expand Down Expand Up @@ -120,12 +127,14 @@ export default class JehonImageLoading extends HTMLElement {
}

// Image is really ready
this.shadowRoot.querySelectorAll('img:not([loading])')
.forEach(img => img.setAttribute('legacy', 'legacy'));
el.removeAttribute('loading');

// Wait for animation to end
await sleep(2 * Math.max(JehonImageLoading.#transitionTimeMs, 1));

this.shadowRoot.querySelectorAll('img:not([loading]):not(:last-of-type)')
this.shadowRoot.querySelectorAll('img[legacy]')
.forEach(img => img.remove());

// Warn the parents
Expand Down

0 comments on commit 7444659

Please sign in to comment.