Particle js background for angular project?

假装没事ソ 提交于 2019-12-03 09:32:16

this is how i got it to work in my NG6 project:

  1. Install particles.js from npm: npm i particles.js --save
  2. Add node_modules/particle.js/particle.js in your scripts section in angular.json
  3. In your component add: declare var particlesJS: any; before @component
  4. Go to particle.js and modify the particles to your liking then download the particlesjs-config.json file
  5. Store that file in your assets/data folder as particles.json
  6. In your component html template add a div with id = "particle-js"
  7. in your component ngOnInit add the following code:

    particlesJS.load('particles-js', 'assets/data/particles.json', function() { console.log('callback - particles.js config loaded'); });

Hope this helps!

EDIT: Added code

import { Component, OnInit } from '@angular/core';
import { ParticlesConfig } from './../../../../../assets/data/particles';

declare var particlesJS: any;

@Component({
  selector: 'app-heading',
  templateUrl: './heading.component.html',
  styleUrls: ['./heading.component.scss']
})
export class HeadingComponent implements OnInit {
    constructor() { }

    ngOnInit() {
        // https://vincentgarreau.com/particles.js/
        particlesJS('particles-js', ParticlesConfig, function() {
            console.log('callback - particles.js config loaded');
          });
    }
}

the template

<div class="h-75 bg header">
    <div  id="particles-js" class="w-100 header-particles"  >

    </div>
    <div class="header-container w-100">
        <div>
            <h1> Big Header</h1>
            <div>small header</div>
        </div>
    </div>
</div>

and the use in another component

<app-heading></app-heading>
<main>
  <app-features></app-features>
  <app-pricing-tier></app-pricing-tier>
  <app-testimonials></app-testimonials>
  <app-trusted-by></app-trusted-by>
</main>
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!