Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

ack-angular-fx

ackerapple204MIT5.0.2TypeScript support: included

Angular animations made easier

Angular animations, Angular fx, ng animations, angular router animations, angular/animations

readme

Description

Angular animations made easy. Example Page

hire me npm version npm downloads Dependency Status

animated gif

Angular 5.2.0+ required

<summary>Table of Contents</summary>

Install

Requirements

Since you're using Angular, the following are expected to already be installed:

  • reflect-metadata
  • @angular/core
  • @angular/animations

install command:

npm install ack-angular-fx --save-dev

Include

Animations must be injected into your components and this is how to do that

import { animations } from "ack-angular-fx";
import { Component } from "@angular/core"

@Component({
  animations:animations,
  template:`
    <div *ngIf="boolean" [@fadeInOutUp]="boolean">
      ...
    </div>
    <button (click)="boolean=!boolean">
      hide or show
    </button>
  `
}) export class AppComponent

Browser Compatibility

All good!

Angular animations have come a long way. In the past, they didn't work in Safari without including additional libraries. Now, all animations appear to be working anywhere that Angular could be run.

Examples

View interactive example page here.

Robust Example

This example has pretty much everything needed to boot

NOTE: AckFxModule, in code below, is only needed IF directive fx-tracker being used for back-n-forth swap animation tracking

import "zone.js"
import "reflect-metadata"
import { platformBrowserDynamic } from "@angular/platform-browser-dynamic"
import { NgModule, Component } from "@angular/core"
import { BrowserModule } from "@angular/platform-browser";
import { BrowserAnimationsModule } from "@angular/platform-browser/animations"

import { animations } from "ack-angular-fx";

//NOTE: This line only needed IF directive fx-tracker used (back-n-forth swap animations)
import { AckFxModule } from "ack-angular-fx";

import { supportDocument } from "ack-angular-fx/web-animations.min"

supportDocument( document )//cross browser fx support

@Component({
  animations:animations,
  template:`
    <div *ngIf="boolean" [@rotateInOut]="boolean">
      ...
    </div>
    <button (click)="boolean=!boolean">
      hide or show
    </button>
  `
}) export class AppComponent

@NgModule({
  imports: [
    BrowserModule,
    BrowserAnimationsModule,
    AckFxModule//NOTE: This line only needed IF directive fx-tracker used (back-n-forth swap animations)
  ],
  declarations: [ AppComponent ],
  bootstrap: [ AppComponent ]
}) export class AppModule {}


platformBrowserDynamic().bootstrapModule(AppModule)

Params Example

The configuration options available to define for animations

<div [@zoomInOut]="{value:boolean, params:{time:'2000ms 0 linear'}}">
  ...
</div>

Learn more about Angular animation timing here

Stagger

Offset multiple animations using Angular 4.2.4 or greater

Currently, staggering animations using ack-angular-fx, is controlled by a parent stagger definition and child animations subscribing to that via the css class "childFx"

Stagger Items Example

A parent container staggering child animations whenever the array adds or removes elements

<div [@childStag]="array.length">
  <div
    *ngFor = "let x of array"
    [@rotateInOut] = "1"
  >
    <div>
      ngFor loop with animations for each
    </div>
  </div>
</div>

Stagger Table Rows Example

A table element staggering row animations whenever "rowStaggers" variable changes value

<table style="width:100%" [@childStag]="array.length">
  <ng-container *ngFor="let x of array">
    <tr [@bounceInOut]="array.length" style="background-color:#CCC">
      <td>{{ x }}</td>
      <td>Item Row {{ x }}</td>
    </tr>
  </ng-container>
</table>

Supported Animations

  • fadeIn
    • fadeInDown, fadeInLeft, fadeInRight, fadeInUp
  • fadeOut
    • fadeOutDown, fadeOutLeft, fadeOutRight, fadeOutUp
  • fadeInOut
    • fadeInOutDown, fadeInOutLeft, fadeInOutRight, fadeInOutUp
  • bounceIn
    • bounceInDown, bounceInLeft, bounceInRight, bounceInUp
  • bounceOut
    • bounceOutDown, bounceOutLeft, bounceOutRight, bounceOutUp
  • bounceIn
    • bounceInOutDown, bounceInOutLeft, bounceInOutRight, bounceInOutUp
  • rotateIn
    • rotateInDownLeft, rotateInDownRight, rotateInUpLeft, rotateInUpRight
  • rotateOut
    • rotateOutDownLeft, rotateOutDownRight, rotateOutUpLeft, rotateOutUpRight
  • rotateInOut
    • rotateInOutDownLeft, rotateInOutDownRight, rotateInOutUpLeft, rotateInOutUpRight
  • zoomIn
    • zoomInDown, zoomInLeft, zoomInRight, zoomInUp
  • zoomOut
    • zoomOutDown, zoomOutLeft, zoomOutRight, zoomOutUp
  • zoomInOut
    • zoomInOutDown, zoomInOutLeft, zoomInOutRight, zoomInOutUp
  • slideInDown, slideInLeft, slideInRight, slideInUp
  • slideOutDown, slideOutLeft, slideOutRight, slideOutUp
  • slideInOutDown, slideInOutLeft, slideInOutRight, slideInOutUp

see online demo https://ackerapple.github.io/ack-angular-fx

Prebuild Fxs to Single File

Known as the prefx process, ack-angular-fx has cli commands to bundle animations to file

This often helps with bundling issues and Angular AOT compilation

Example Compile All Animations to One File

Step 1 : Add the following to your package.json scripts

"scripts":{
  "build:prefx": "ack-angular-fx --out ./src/prefx.ts"
}

Step 2 : Now, run the following in a command prompt terminal

npm run build:prefx

After the above command you should now see a prefx.ts file in your src folder

Step 3 : Import your compiled .ts file and apply to component(s)

import { animations } from "./prefx"
import { Component } from "@angular/core"

@Component({
  selector: 'app',
  template: '<div *ngIf="a==1" [@fadeInUp]="true">hello world</div>',
  animations: animations
})

Work on This Project

Everything in this topic is run in an command prompt terminal

Clone this project

git clone https://github.com/AckerApple/ack-angular-fx

Dev Fast Project Watching

npm run watch

Build before commit

npm run build

Credits

A special thank you goes out to yuyang041060120 for creating ng2-animate and for taking too long to respond to my pull request, which has led to the birth of ack-angular-fx.

Table of Contents

Resources

changelog

ack-angular-fx - Change Log

All notable changes to this project will be documented here.

[4.2.0] - 2022-01-04

  • Add peerDependencies

[3.0.4] - 2019-05-26

  • Fix tracking history by orderArray

[3.0.3] - 2019-05-18

  • better fx-tracker history

[3.0.2] - 2019-04-17

  • Added fx-tracker inFx helper

[3.0.1] - 2019-03-19

  • fx-tracker uses Promise.resolve().then(()=>) instead of setTimeout

[3.0.0] - 2019-02-13

  • Added Out
    • fadeOut
  • Updated dependencies
  • Breaking Changes
    • Removed "Global Usage" injection that came via
    • all in Kids animations like fadeInKids is renamed to fadeInOutKids
    • In is now InOut
      • fadeIn is now fadeInOut
      • fadeIn only transistions in but not out anymore
    • "fxArray" is renamed to "animations"
      • import { animations } from "ack-angular-fx"

[2.3.0] - 2018-11-16

  • Updated Angular

[2.2.1] - 2018-09-28

  • fix file refs

[2.2.0] - 2018-09-28

  • Upgraded to Angular6
  • deprecated fxId and fxIdChange
    • use <fx-tracker #fx="FxTracker"></fx-tracker>
    • fx.id
  • removed web-animations-js

[2.1.2] - 2018-04-12

  • Made all basic animations animate even when false or 0 are based in
    • Condition to check to animate was ignoring false or 0
    • Pass 'nofx' when you dont want animation

[2.1.1] - 2018-03-03

  • Added router-outlet documentation
  • Fixed FxTracker value tracking when activeRouter monitoring

[2.1.0] - 2018-03-01

  • improved file size by deprecating Angular4 animations
  • Breaking Changes
    • Removed [@100],[@200],[@300],[@400],[@500],...
    • Removed [@absoluteSwap],[@absoluteSwap100],[@absoluteSwap200],...

[2.0.11] - 2018-03-01

  • allFx file is now a prefx file and apart of the ack-angular-fx process

[2.0.9] - 2018-03-01

  • all animation transition functions are exported

[2.0.8] - 2018-02-28

  • Updated README file

[2.0.6] - 2018-02-23

  • added transistion function interpolation
    • with options compiled as well
  • fix rotate animations

[2.0.0] - 2018-02-22

  • prefx compiling seems no longer required

    Breaking Changes

  • upgraded to Angular5. Angular5 is required to use this package
  • old stuff should still work but is becoming deprecated

[1.2.5] - 2017-07-06

Fixed

  • user reported issue

    Changed

  • 500 max to 300 for childStag

[1.2.0] - 2017-06-29

Breaking Changes

  • Angular 4.2.4 is now required

    Added

  • query, stagger, animateChild support
  • new childStag trigger to support staggering

[1.1.0] - 2017-03-30

Fixed

  • Made more AoT compatible by making AnimationTriggerMetadata available to prefx outputs

[1.0.11] - 2017-03-20

Added

  • Better docs

[1.0.6] - 2017-03-16

Added

  • AoT support by making static prefx animations

[1.0.5] - 2017-03-09