wagerfield/parallax

Using Parallaxjs in Angular 8

lion9010 opened this issue · 0 comments

If you are using Angular, must to import third-party libraries and the process was complicated to me and I could solved it with this... if you have a better solution, pls, write it... Then:

  1. Download
    npm -s install parallax-js
    and
    npm install typings -g --save-dev

  2. Because it doesn't have typings available at @types/ you must to create a document

src>typings.d.ts

  1. Declare module in typings.d.ts and export the function void to implement later "new"
declare module 'parallax-js' {
    export interface parallax {}
    export function Parallax(scene:any, optionns?:object): void;
}
  1. import ngAfterContentInit in yout .ts component because it must to read first all your html to use Parallax and declare "require" before of decorator Component.
import { Component, AfterContentInit } from '@angular/core';

declare let require: any;

@Component({...})
  1. implement AfterContentInit in your class component

  2. And Use Parallax importing with "require" into the ng()

export class AppComponent implements AfterContentInit {

  ngAfterContentInit() {
    const Parallax = require('parallax-js');
    const scene = document.getElementById('scene');
    const parallaxInstance = new Parallax(scene, {
      relativeInput: true
    });
  }
}