aboutsummaryrefslogtreecommitdiff
path: root/src/lib/BackgroundImage.svelte
diff options
context:
space:
mode:
authormat <github@matdoes.dev>2022-03-04 23:05:09 -0600
committermat <github@matdoes.dev>2022-03-04 23:05:09 -0600
commite2506cac822f0b5ddbc285880c768eda9357e075 (patch)
tree0ca4f9dee04a0d51f6d3a939c9543fbf9e6d779c /src/lib/BackgroundImage.svelte
parent453872fa0587040cf56f5ba72d92042542836afc (diff)
downloadskyblock-stats-e2506cac822f0b5ddbc285880c768eda9357e075.tar.gz
skyblock-stats-e2506cac822f0b5ddbc285880c768eda9357e075.tar.bz2
skyblock-stats-e2506cac822f0b5ddbc285880c768eda9357e075.zip
dynamic packs and bug fixes
Diffstat (limited to 'src/lib/BackgroundImage.svelte')
-rw-r--r--src/lib/BackgroundImage.svelte26
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>