aboutsummaryrefslogtreecommitdiff
path: root/src/lib/BackgroundImage.svelte
blob: 94bbc3fcea8ee3edcaa6294e560a8bb643e7f5db (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<script lang="ts">
	import { browser } from '$app/env'

	import { onDestroy } from 'svelte'

	export let url: string

	// cursed svelte :D
	$: bodyStyle =
		'<sty' + 'le id="background-image-style">:root{--background:url(' + url + ')}</st' + 'yle>'

	// get rid of the body style when we leave the page
	// not doing this will sometimes cause the background to stay
	onDestroy(() => {
		bodyStyle = ''
		// hack since sometimes the style is not removed
		if (browser) {
			let styleEl = document.getElementById('background-image-style')
			if (styleEl) styleEl.innerHTML = ''
		}
	})
</script>

<svelte:head>
	{@html bodyStyle}
</svelte:head>