2023-07-08 19:23:27 +02:00
|
|
|
<template>
|
|
|
|
<ClientOnly>
|
|
|
|
<transition name="fade">
|
|
|
|
<div v-if="particleEnabled" ref="container" class="absolute top-0 left-0 w-full h-[800px] select-none pointer-events-none" :style="colorVars"></div>
|
|
|
|
</transition>
|
|
|
|
</ClientOnly>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script setup lang="ts">
|
|
|
|
import { Loader } from '@/assets/js/particles/loader';
|
|
|
|
|
|
|
|
const colorMode = useColorMode();
|
|
|
|
const container = ref<HTMLElement>();
|
|
|
|
const isMounted = ref<boolean>(false);
|
|
|
|
const particleEnabled = ref<boolean>(true);
|
|
|
|
|
|
|
|
const colorVars = computed<string>(() => {
|
2023-07-09 20:09:50 +02:00
|
|
|
const out = [`--c-brand: #86b300;`];
|
|
|
|
if (colorMode.value == 'dark') {
|
|
|
|
out.push(`--c-text: rgb(226 232 240);`);
|
|
|
|
} else {
|
|
|
|
out.push(`--c-text: rgb(51 65 85);`);
|
2023-07-08 19:23:27 +02:00
|
|
|
}
|
|
|
|
return out.join(' ');
|
|
|
|
});
|
|
|
|
|
|
|
|
onMounted(() => {
|
|
|
|
isMounted.value = true;
|
|
|
|
});
|
|
|
|
|
2023-07-09 20:09:50 +02:00
|
|
|
let loader: Loader;
|
|
|
|
|
2023-07-08 19:23:27 +02:00
|
|
|
watch(container, (to) => {
|
2024-03-29 14:59:41 +01:00
|
|
|
if (isMounted.value && import.meta.client && to) {
|
2023-07-09 20:09:50 +02:00
|
|
|
loader = new Loader(to);
|
2023-07-08 19:23:27 +02:00
|
|
|
|
|
|
|
window.addEventListener('scroll', () => {
|
|
|
|
particleEnabled.value = false;
|
|
|
|
}, {
|
|
|
|
passive: true,
|
|
|
|
once: true,
|
|
|
|
});
|
|
|
|
|
|
|
|
}
|
|
|
|
})
|
2023-07-09 20:09:50 +02:00
|
|
|
|
|
|
|
onUnmounted(() => {
|
|
|
|
setTimeout(() => {
|
|
|
|
loader.destroy();
|
|
|
|
}, 1);
|
|
|
|
});
|
|
|
|
|
2023-07-08 19:23:27 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style>
|
|
|
|
.fade-enter-active,
|
|
|
|
.fade-leave-active {
|
|
|
|
transition: opacity 1s ease;
|
|
|
|
}
|
|
|
|
|
|
|
|
.fade-enter-from,
|
|
|
|
.fade-leave-to {
|
|
|
|
opacity: 0;
|
|
|
|
}
|
|
|
|
</style>
|