vue3 vue3-particles粒子使用方法

如果有遇到报错:TypeError: interactor.init is not a function

请把tsparticles版本降到2.12.0

npm i tsparticles@2.12.0

注意:这个vue3-particlesparticles.vue3有些许差别的(安装、引入方式)

particles.vue3示例:vue3 使用particles插件粒子_vueparticles_余温无痕的博客-CSDN博客

下面是vue3-particles使用介绍

先看效果,背景图是自己设置的

安装:

// 这两个都要安装

npm i vue3-particles

npm i tsparticles@2.12.0  // 不要3版本以上,会报错TypeError: interactor.init is not a function

 在main.js中引用

import Particles from "vue3-particles"

const app = createApp(App);
app.use(Particles).mount("#app")

页面上,更新了放置背景图片的css

<template>
    <div class="login-bg">
        <vue-particles id="tsparticles" :particlesInit="particlesInit" :particlesLoaded="particlesLoaded" :options="data.options" />
    </div>
</template>

<script setup>
import { loadFull } from "tsparticles"
    
const data = reactive({
    options: {
        fpsLimit: 100,
        interactivity: {
            events: {
                onClick: {
                    enable: true,
                    mode: "push",
                },
                onHover: {
                    enable: true,
                    mode: "grab",
                },
                resize: true,
            },
            modes: {
                bubble: {
                    distance: 400,
                    duration: 2,
                    opacity: 0.6,
                    size: 10,
                },
                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,
                outMode: "bounce",
                random: false,
                speed: 2,
                straight: false,
            },
            number: {
                density: {
                    enable: true,
                    value_area: 800,
                },
                value: 60,
            },
            opacity: {
                value: 0.5,
            },
            shape: {
                type: "circle",
            },
            size: {
                random: true,
                value: 3,
            },
        },
        detectRetina: true,
    },
})

// 粒子效果
const particlesInit = async (engine) => {
   await loadFull(engine)
}
const particlesLoaded = async (container) => {
   // console.log("Particles container loaded", container)
}
</script>
<style lang="less" scoped>
/**放置背景图片 */
.login-bg {
    width: 100%;
    height: 100%;
    background: url("xxx") no-repeat
        center;
    background-size: cover;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    overflow: hidden;
    position: relative;
}
</style>

 APP.vue——跟设置背景图片有关

<div class="view-box"></div>

<style lang="less">
.app-box {
    width: 100%;
    height: 100%;
}
</style>

公共css ——跟设置背景图片有关

html,
body {
    height: 100%; 
}

#app {
    height: 100%;
}

相关链接 

GitHub - tsparticles/vue3: Vue.js tsParticles official componentVue.js tsParticles official component. Contribute to tsparticles/vue3 development by creating an account on GitHub.icon-default.png?t=N7T8https://github.com/tsparticles/vue3

Demo: 

tsParticles | JavaScript Particles, Confetti and Fireworks animations for your website

  • 3
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 8
    评论
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

余温无痕

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值