react实现粒子动画

首先安装依赖

npm i reactparticles.js --save

简单用法,引入当做标签用,id必填任意不重复即可,config指向public下存放的.json配置文件,配置文件可以自己改,也可以去官网生成:

地址:https://github.com/kr1tzb1tz/reactparticles.js

//引入

import Particles from 'reactparticles.js';

在render中使用

<Particles id="test-particles" config="test-particles.json"/>
扫描二维码关注公众号,回复: 5130271 查看本文章

public下的test-particles.json文件内容如下:

{

"particles": {

"number": {

"value": 100,

"density": {

"enable": false,

"value_area": 800

}

},

"color": {

"value": "#ffffff"

},

"shape": {

"type": "image",

"stroke": {

"width": 0,

"color": "#000000"

},

"polygon": {

"nb_sides": 5

},

"image": {

"src": "./img/coin_bagshare.png",

"width": 50,

"height": 50

}

},

"opacity": {

"value": 1,

"random": true,

"anim": {

"enable": true,

"speed": 1,

"opacity_min": 0,

"sync": false

}

},

"size": {

"value": 10,

"random": false,

"anim": {

"enable": false,

"speed": 4,

"size_min": 0.3,

"sync": false

}

},

"line_linked": {

"enable": false,

"distance": 0,

"color": "#ffffff",

"opacity": 0.4,

"width": 1

},

"move": {

"enable": true,

"speed": 1,

"direction": "none",

"random": true,

"straight": false,

"out_mode": "out",

"bounce": false,

"attract": {

"enable": false,

"rotateX": 600,

"rotateY": 600

}

}

},

"interactivity": {

"detect_on": "window",

"events": {

"onhover": {

"enable": false,

"mode": "bubble"

},

"onclick": {

"enable": false,

"mode": "push"

},

"resize": true

},

"modes": {

"grab": {

"distance": 100,

"line_linked": {

"opacity": 1

}

},

"bubble": {

"distance": 250,

"size": 0,

"duration": 2,

"opacity": 0,

"speed": 3

},

"repulse": {

"distance": 400,

"duration": 0.4

},

"push": {

"particles_nb": 4

},

"remove": {

"particles_nb": 2

}

}

},

"retina_detect": false

}

最终实现效果:

会上下左右缓慢移动组合等等,根据自身json配置表配置。

猜你喜欢

转载自blog.csdn.net/baidu_38027860/article/details/84580063