【NPM】particles.vue3 + tsparticles 实现粒子效果

在 NPM 官网搜索这两个库并安装:

复制代码
npm install element-plus --save
npm i tsparticles

使用提供的 vue 案例和方法:

html 复制代码
<template>
  <div>
    <vue-particles
      id="tsparticles"
      :particlesInit="particlesInit"
      :particlesLoaded="particlesLoaded"
      :options="{
        background: {
          color: {
            value: '#0d47a1'
          }
        },
        fpsLimit: 120,
        interactivity: {
          events: {
            onClick: {
              enable: true,
              mode: 'push'
            },
            onHover: {
              enable: true,
              mode: 'repulse'
            },
            resize: true
          },
          modes: {
            bubble: {
              distance: 400,
              duration: 2,
              opacity: 0.8,
              size: 40
            },
            push: {
              quantity: 4
            },
            repulse: {
              distance: 200,
              duration: 0.4
            }
          }
        },
        particles: {
          color: {
            value: '#ffffff'
          },
          links: {
            color: '#ffffff',
            distance: 150,
            enable: true,
            opacity: 0.5,
            width: 1
          },
          collisions: {
            enable: true
          },
          move: {
            direction: 'none',
            enable: true,
            outModes: {
              default: 'bounce'
            },
            random: false,
            speed: 6,
            straight: false
          },
          number: {
            density: {
              enable: true,
              area: 800
            },
            value: 80
          },
          opacity: {
            value: 0.5
          },
          shape: {
            type: 'circle'
          },
          size: {
            value: { min: 1, max: 5 },
          }
        },
        detectRetina: true
      }"
    />
  </div>
</template>

<script setup>
import { loadFull } from "tsparticles";
const particlesInit = async engine => {
  await loadFull(engine);
  // await loadSlim(engine);
};
</script>

<style lang="scss" scoped></style>

即可出现粒子效果。

相关推荐
telllong5 分钟前
C++20 Modules:从入门到真香
java·前端·c++20
齐鲁大虾22 分钟前
如何在HTML/JavaScript中禁用Ctrl+C
前端·javascript·html
qq_4061761438 分钟前
深入浅出 Vue 路由:从基础到进阶全解析
前端·javascript·vue.js
陈随易1 小时前
MoonBit访谈:MoonBit开发moonclaw实现“养虾”自由
前端·后端·程序员
汀沿河1 小时前
3 LangChain 1.0 中间件(Middleware)- after_model、after_agent
前端·中间件·langchain
紫金修道1 小时前
【OpenClaw】让openclaw根据需求创造自定义skill记录
前端·javascript·chrome
周杰伦fans1 小时前
Edge浏览器 about:blank 问题修复
前端·数据库·edge
嘉琪0011 小时前
Day6 完整学习包(async/await)——2026 0318
前端·javascript·学习
SameX1 小时前
我做了个本地优先的 iOS 足迹 App,上架后才发现:最难的根本不是地图,而是让轨迹活下来
前端
踩着两条虫1 小时前
AI 驱动的 Vue3 应用开发平台 深入探究(十八):扩展与定制之集成第三方库
前端·vue.js·agent