Files
marco/app/modifiers/fade-in-image.js
Râu Cao 85a8699b78 Render header photo in place details
Shows the blurhash and fades in the image once downloaded
2026-04-21 23:07:06 +04:00

31 lines
733 B
JavaScript

import { modifier } from 'ember-modifier';
export default modifier((element, [url]) => {
if (!url) return;
// Remove classes when URL changes
element.classList.remove('loaded');
element.classList.remove('loaded-instant');
// Create an off-DOM image to reliably check cache status
// without waiting for the actual DOM element to load it
const img = new Image();
img.src = url;
if (img.complete) {
// Already in browser cache, skip the animation
element.classList.add('loaded-instant');
return;
}
const handleLoad = () => {
element.classList.add('loaded');
};
element.addEventListener('load', handleLoad);
return () => {
element.removeEventListener('load', handleLoad);
};
});