Angular6使用粒子特效外掛particlejs
阿新 • • 發佈:2018-12-21
1.安裝angular-particle
npm install angular-particle --save
2.使用該元件的module.ts中匯入模組
3.對應的html中
<particles [params]="myParams" [style]="myStyle" [width]="width" [height]="height"></particles>
4.對應的component.ts中定義如下
import { Component, OnInit } from '@angular/core';
@Component ({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent implements OnInit {
myStyle: object = {};
myParams: object = {};
width: number = 100;
height: number = 100;
ngOnInit() {
this.myStyle = {
'position': 'fixed' ,
'width': '100%',
'height': '100%',
'z-index': -1,
'top': 0,
'left': 0,
'right': 0,
'bottom': 0,
'background-color': '#ccc'
};
this.myParams = {
particles: {
number: {
value: 80,
},
color: {
value: '#fff'
},
shape: {
type: 'triangle',
},
move:{
attract:{
enable:true
}
}
}
};
}
效果圖: