Angular6使用粒子特效插件particlejs

本文介绍了如何在Angular6项目中使用粒子特效插件particlejs,包括安装angular-particle,模块导入,HTML和Component.ts的配置,以及最终实现的粒子特效截图。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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
          }
        }
      }
    };
}

效果图:
在这里插入图片描述

< DOCTYPE html> <html ang app ""> <head> < <link rel "stylesheet" href "http: apps bdimg com libs bootstrap 3 2 0 css bootstrap min css"> > < head> <body ng controller "userController"> <div class "container"> <h3>Users< h3> <table class "table table striped"> <thead><tr> <th>Edit< th> <th>First Name< th> <th>Last Name< th> < tr>< thead> <tbody><tr ng repeat "user in users"> <td> <button class "btn" ng click "editUser user id "> < <span class "glyphicon glyphicon pencil">< span>&nbsp;&nbsp;Edit > < button> < td> <td>{{ user fName }}< td> <td>{{ user lName }}< td> < tr>< tbody> < table> <hr> <button class "btn btn success" ng click "editUser "new" "> <span class "glyphicon glyphicon user">< span> Create New User < button> <hr> <h3 ng show "edit">Create New User:< h3> <h3 ng hide "edit">Edit User:< h3> <form class "form horizontal"> <div class "form group size13"> <label style "float:left" class "col sm 2 control label">Email地址:< label> <div class "col sm 10"> <input style "height: 30px;width: 330px;" type "text" ng model "fName" > < div> < div> <div class "form group"> <label style "float:left" class "col sm 2 control label">Last Name:< label> <div class "col sm 10"> <input style "height: 30px;width: 330px;" type "text" ng model "lName" placeholder "Last Name"> < div> < div> <div class "form group"> <label style "float:left" class "col sm 2 control label">Password:< label> <div class "col sm 10"> <input style "height: 30px;width: 330px;" type "password" ng model "passw1" placeholder "Password"> < div> < div> <div class "form group"> <label style "float:left" class "col sm 2 control label">Repeat:< label> <div class "col sm 10"> <input style "height: 30px;width: 330px;" class "size14 "type "password" ng model "passw2" placeholder "Repeat Password"> < div> < div> < form> <hr> <div> <button class "btn btn success" ng disabled "error || incomplete"> 更新 < button> < div> <script src "http: apps bdimg com libs angular js 1 2 15 angular min js">< script> <script src "myUsers js"> function userController $scope { $scope fName ""; $scope lName ""; $scope passw1 ""; $scope passw2 ""; $scope users [ {id:1 fName:"Hege" lName:"Pege" } {id:2 fName:"Kim" lName:"Pim" } {id:3 fName:"Sal" lName:"Smith" } {id:4 fName:"Jack" lName:"Jones" } {id:5 fName:"John" lName:"Doe" } {id:6 fName:"Peter" lName:"Pan" } ]; $scope edit true; $scope error false; $scope incomplete false; $scope editUser function id { if id "new" { $scope edit true; $scope incomplete true; $scope fName ""; $scope lName ""; } else { $scope edit false; $scope fName $scope users[id 1] fName; $scope lName $scope users[id 1] lName; } }; $scope $watch "passw1" function {$scope test ;} ; $scope $watch "passw2" function {$scope test ;} ; $scope $watch "fName" function {$scope test ;} ; $scope $watch "lName" function {$scope test ;} ; $scope test function { if $scope passw1 $scope passw2 { $scope error true; } else { $scope error false; } $scope incomplete false; if $scope edit && $scope fName length || $scope lName length || $scope passw1 length || $scope passw2 length { $scope incomplete true; } }; } < script> < body> < html>>">< DOCTYPE html> <html ang app ""> <head> < <link rel "stylesheet" href "http: apps bdimg com libs bootstrap 3 2 0 css bootstrap min css"> > < head> <body ng controller "userController"> <div class "con [更多]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值