动态背景组件(vue-particles)

启用 vue-particles 粒子背景插件(main.js)

import VueParticles from 'vue-particles'

Vue.use(VueParticles)

动态背景组件(AnimatedWallpaper.vue)

<template>
  <div :style="style">
    <vue-particles
        color="#ffffff"
        :particleOpacity="0.7"
        :particlesNumber="number"
        shapeType="circle"
        :particleSize="3"
        linesColor="#E6E6FA"
        :linesWidth="1"
        :lineLinked="linked"
        :lineOpacity="0.6"
        :linesDistance="150"
        :moveSpeed="speed"
        :hoverEffect="true"
        hoverMode="grab"
        :clickEffect="true"
        :clickMode="mode"
    >
    </vue-particles>
    <slot></slot>
  </div>
</template>

<script>
export default {
  name: "AnimatedWallpaper",
  props: {
    bgImg: {
      type: String,
      default: require('@/assets/nap.jpg')
    },
    number: {
      type: Number,
      default: 50 // 100
    },
    linked: {
      type: Boolean,
      default: true // false
    },
    speed: {
      type: Number,
      default: 6 // 8
    },
    mode: {
      type: String,
      default: "push" // "repulse"
    }
  },
  data() {
    return {
      style: {
        background: 'url(' + this.bgImg + ') no-repeat top',
        backgroundSize: 'cover',
        backgroundAttachment: 'fixed',
        height: '100%',
        width: '100%',
        position: 'fixed',
        overflow: 'scroll',
        zIndex: -99999
      }
    }
  }
}
</script>

<style scoped>
  #particles-js {
    position: fixed;
    width: 100%;
    height: 100%;
    background-repeat: no-repeat;
    background-size: cover;
    background-position: 50% 50%;
    z-index: -99998;
  }

  ::-webkit-scrollbar {
    display: none;
  }
</style>

使用方式

<template>
  <div>
<!--    <animated-wallpaper />-->

<!--    <animated-wallpaper :bg-img="require('@/assets/20_21.jpg')" />-->

    <animated-wallpaper
      :number="100"
      :linked="false"
      :speed="8"
      mode="repulse"
      :bg-img="require('@/assets/Emilia.jpg')"
    />
  </div>
</template>

<script>
import AnimatedWallpaper from "@/components/AnimatedWallpaper";

export default {
  name: "Trial",
  components: {
    AnimatedWallpaper
  }
}
</script>

<style scoped>

</style>

效果图

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

  • 3
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值