Using Parallaxjs in Angular 8
lion9010 opened this issue · 0 comments
lion9010 commented
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:
-
Download
npm -s install parallax-js
and
npm install typings -g --save-dev
-
Because it doesn't have typings available at @types/ you must to create a document
src>typings.d.ts
- 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;
}
- 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({...})
-
implement AfterContentInit in your class component
-
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
});
}
}