Git Product home page Git Product logo

ng-ionic-animate's Introduction

ng-ionic-animate GitHub release Build Status devDependencies Status

ng-ionic-animate is a helpful site for learning angular animations.

Using Animations

Angular animations are built on top of the standard Web Animations API and run natively on browsers that support it.

Animations are defined inside @Component metadata. Before you can add animations, you need to import a few animation-specific imports and functions:

app.module.ts

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
@NgModule({
  ...
  imports: [
    ...
    BrowserModule,
    BrowserAnimationsModule
  ]
  ...
})

page-where-i-want-animations.ts

Add the following as needed imports into the page's .ts file where you want to use animations:

import {
  trigger,
  state,
  style,
  animate,
  transition
} from '@angular/animations';

Heroes example from angular's website:

Below is the heroes animation example from Angular's site

import {
  Component,
  Input
} from '@angular/core';
import {
  trigger,
  state,
  style,
  animate,
  transition
} from '@angular/animations';
 
import { Heroes } from './hero.service';
 
@Component({
  selector: 'hero-list-basic',
  template: `
    <ul>
      <li *ngFor="let hero of heroes"
          [@heroState]="hero.state"
          (click)="hero.toggleState()">
        {{hero.name}}
      </li>
    </ul>
  `,
  styleUrls: ['./hero-list.component.css'],
  animations: [
    trigger('heroState', [
      state('inactive', style({
        backgroundColor: '#eee',
        transform: 'scale(1)'
      })),
      state('active',   style({
        backgroundColor: '#cfd8dc',
        transform: 'scale(1.1)'
      })),
      transition('inactive => active', animate('100ms ease-in')),
      transition('active => inactive', animate('100ms ease-out'))
    ])
  ]
})
export class HeroListBasicComponent {
  @Input() heroes: Heroes;
}

Safari Support

In order to get animations to work in safari you must add the following polyfill:

  1. npm install web-animations-js --save
  2. Under src > app > main.ts add the following import:
import 'web-animations-js/web-animations.min';

License

ng-ionic-animate is licensed under the MIT license. (http://opensource.org/licenses/MIT)

ng-ionic-animate's People

Contributors

sarahtully avatar

Watchers

 avatar

Forkers

mopi1402

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.