diff options
Diffstat (limited to 'src/lib/BackgroundImage.svelte')
-rw-r--r-- | src/lib/BackgroundImage.svelte | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/src/lib/BackgroundImage.svelte b/src/lib/BackgroundImage.svelte new file mode 100644 index 0000000..c059119 --- /dev/null +++ b/src/lib/BackgroundImage.svelte @@ -0,0 +1,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.remove() + } + }) +</script> + +<svelte:head> + {@html bodyStyle} +</svelte:head> |