Skip to content

Commit c5d9a08

Browse files
committed
feat: add ParticlesBackground component with particle effects
1 parent d462e41 commit c5d9a08

File tree

2 files changed

+137
-0
lines changed

2 files changed

+137
-0
lines changed

docs/.vuepress/client.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { defineClientConfig } from "@vuepress/client";
2+
import Particles from "vue3-particles";
3+
import ParticlesBackground from "./components/ParticlesBackground.vue";
4+
5+
export default defineClientConfig({
6+
enhance({ app }) {
7+
app.use(Particles);
8+
},
9+
10+
setup() {},
11+
12+
rootComponents: [ParticlesBackground],
13+
});
Lines changed: 124 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
<template>
2+
<div class="particles-wrapper">
3+
<Particles
4+
id="tsparticles"
5+
:particlesInit="particlesInit"
6+
:options="particleOptions"
7+
/>
8+
</div>
9+
</template>
10+
11+
<script setup>
12+
import { computed, ref, onMounted } from "vue";
13+
import { loadSlim } from "tsparticles-slim";
14+
15+
const isDark = ref(false);
16+
17+
onMounted(() => {
18+
if (typeof document !== "undefined") {
19+
isDark.value = document.documentElement.classList.contains("dark");
20+
21+
const observer = new MutationObserver(() => {
22+
isDark.value = document.documentElement.classList.contains("dark");
23+
});
24+
25+
observer.observe(document.documentElement, {
26+
attributes: true,
27+
attributeFilter: ["class"],
28+
});
29+
}
30+
});
31+
32+
const particlesInit = async (engine) => {
33+
await loadSlim(engine);
34+
};
35+
36+
const particleOptions = computed(() => ({
37+
background: {
38+
color: {
39+
value: "transparent",
40+
},
41+
},
42+
fpsLimit: 60,
43+
interactivity: {
44+
events: {
45+
onClick: {
46+
enable: false,
47+
mode: "push",
48+
},
49+
onHover: {
50+
enable: true,
51+
mode: "repulse",
52+
},
53+
resize: true,
54+
},
55+
modes: {
56+
push: {
57+
quantity: 2,
58+
},
59+
repulse: {
60+
distance: 120,
61+
duration: 0.6,
62+
},
63+
},
64+
},
65+
particles: {
66+
color: {
67+
value: "#ff4e3c",
68+
},
69+
links: {
70+
color: "#ff4e3c",
71+
distance: 120,
72+
enable: true,
73+
opacity: isDark.value ? 0.2 : 0.15,
74+
width: 1,
75+
},
76+
collisions: {
77+
enable: false,
78+
},
79+
move: {
80+
direction: "none",
81+
enable: true,
82+
outModes: {
83+
default: "out",
84+
},
85+
random: true,
86+
speed: 0.6,
87+
straight: false,
88+
},
89+
number: {
90+
density: {
91+
enable: true,
92+
area: 800,
93+
},
94+
value: 50,
95+
},
96+
opacity: {
97+
value: isDark.value ? 0.4 : 0.2,
98+
},
99+
shape: {
100+
type: "circle",
101+
},
102+
size: {
103+
value: { min: 1, max: 2 },
104+
},
105+
},
106+
detectRetina: true,
107+
}));
108+
</script>
109+
110+
<style scoped>
111+
/* .particles-wrapper {
112+
position: fixed;
113+
top: 0;
114+
left: 0;
115+
width: 100%;
116+
height: 100%;
117+
z-index: -1;
118+
pointer-events: none;
119+
}
120+
121+
.particles-wrapper:hover {
122+
pointer-events: auto;
123+
} */
124+
</style>

0 commit comments

Comments
 (0)