Angular

How To Use Parallax-js In Angular

In this blog, we will see how to use the Parallax-js effect in angular.

What is Parallax-js, and how does it work?

At the start of the document’s body, parallax.js will construct a fixed-position element for each parallax image. This mirror element will lie behind the other elements, matching the target object’s location and proportions.

Because of the nature of this implementation, you must make these parallax objects and any layers beneath them transparent in order to see the parallax effect underneath. Also, if this element has no other content, you’ll need to make sure it has some fixed dimensions, or you won’t be able to see anything.

Let’s Implement it,

We can use @angular/CLI to create a new Angular Project for this demo.

Use the following command in your terminal window:

$ ng new $ ng new AngularParallaxJsDemo

This will create a new Angular project with CSS styles (rather than SassLess, or Stylus), no routing, and no tests.

Go to the newly created project folder:

$ cd AngularParallaxJsDemo

1. Install

Now, we can install the Parallax-js npm package.

npm -s install parallax-js

And also We can install Typings npm package.

npm install typings -g --save-dev

2. Add Typings Class

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

src>typings.d.ts

3. Declare module in typings.d.ts

Declare the module in typings.d.ts and expose the void function so the “new” feature can be implemented later.

declare module 'parallax-js' {
    export interface parallax {}
    export function Parallax(scene:any, optionns?:object): void;
}

4. Import ngAfterContentInit in your .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({...})

 

Then, implement AfterContentInit in your class component.

5.  Use Parallax importing with “require”.

export class AppComponent implements AfterContentInit {

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

Now it’s done.

OUTPUT:

 

I hope you guys understand how I can do this. Let me know if you face any difficulties.

You can watch my previous blog here.

Happy Coding {;}

Nayan Raval

Nayan Raval is a MEAN Stack .Net Developer has extensive experience with designing and developing enterprise-scale applications. Key Areas Of Expertise: • ASP.NET Core MVC • ASP.NET Core Web API • C# • ASP.NET MVC 5 • Angular All versions • HTML5 • CSS3 / SCSS • Bootstrap • JavaScript • Azure • JQuery Databases and related • Microsoft SQL server MSSQL • PostgreSQL • Entity Framework (EF) • LINQ UI Frameworks • Kendo UI • Telerik • JQuery UI • Prime NG and Material UI API Integration • SignalR • DateDog • Twilio Voice Call And Message • Stripe • SendGrid (Email Camping) • Checkr • Zoom Video Call • Auth0 • Elastic Search • Quartz - Scheduler • JWT Token • Google Calendar

Recent Posts

Testing hk

Testing

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

Operation

Testing

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

Create and Used PIPE in angular

In this article, we have to show Create and Used PIPE in angular

2 years ago

TETS NEW

test

3 years ago