Particle js background for angular project?

ε祈祈猫儿з 提交于 2019-12-04 13:16:25

问题


Can anyone explain how to add particle js background for angular 6 project? I followed some tutorials as bellow link.but it didn't work for me. https://github.com/VincentGarreau/particles.js/

Thank you.


回答1:


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>


来源:https://stackoverflow.com/questions/52143176/particle-js-background-for-angular-project

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