Skip to content

Fade in loaded images with blurhash background [Sveltekit] #675

Closed Answered by maumercado
maumercado asked this question in Q&A
Discussion options

You must be logged in to vote

Feel free to close this, I found my answer here #211

What I ended up doing was wrapping the Image on a div, added the blurred bacgkround to that's div style prop like so:

<script>

	const onLoadImage = (() => {
		document.querySelector('.post-image')?.classList.add('fade-in-image');
	});
</script>

	<article class="post-wrapper">
	<h1 class="post-title">{title}</h1>
	<div class="background-blur" style={`background-image: ${placeholder}` }>
	<Image
		class="post_image"
		layout="fullWidth"
		src={photo_metadata.urls.full}
		alt={photo_metadata.alt_description}
		loading="lazy"
		height={450}
		on:load={onLoadImage}
	/>
	</div>
	{@html content}
</article>

And last the post-image and fade-in…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by maumercado
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant