Coder Social home page Coder Social logo

aaron-sterling / angular-animation-looper Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 69 KB

Dynamic looping of Angular animation. Specify an animation and a number of iterations, and the animation will repeat for that many iterations. You can change the number of iterations programmatically.

TypeScript 35.02% HTML 26.93% CSS 30.35% JavaScript 7.71%
angular animation angular-animation animations loop looper looping ionic angular-animations

angular-animation-looper's Introduction

angular-animation-looper

Dynamic looping of Angular animations. Define an animaton with keyframes, specify a number of iterations, and the animation will repeat for that many iterations. You can change the number of iterations programmatically.

Installation

npm install angular-animation-looper --save

Sample usage

In your template:

<div [@sampleTrigger]="animationState" 
     (@sampleTrigger.done)="loop.next('sampleTrigger')">
</div>

In app.module.ts:

import { BrowserModule } from '@angular/platform-browser';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { LoopAnimationModule } from 'angular-animations-looper';

@NgModule({
  declarations: [],
  imports: [
    BrowserModule,
    BrowserAnimationsModule, // IMPORTANT: You must import these modules in this order
    LoopAnimationModule
  ],
  bootstrap: [],
  entryComponents: [],
  providers: []
})
export class AppModule {}

In the ts file for your template:

import { LoopAnimationService, loopableAnimation } from 'angular-animations-looper';

import ANIMATION_TO_LOOP from './animation-definition';  // this looks like : animate(starting state, keyframes)
const LOOPABLE_ANIMATION = loopableAnimaton(ANIMATION_TO_LOOP);

@Component({

  animations: [ LOOPABLE_ANIMATION ]; // declare the loopable animation in the component
})
export class SampleClass {

    constructor(public loop: LoopAnimationService) {  // <-- inject this service

    this.loop.registerAnimation('sampleTrigger', LOOPABLE_ANIMATION, 7);  // this animation will loop 7 times once it is started
    this.loop.currentState('sampleTrigger').subscribe(state => this.animationState = state); // required so the service can talk to the trigger in the template
    this.loop.startAnimation('sampleTrigger');  // starts the looping animation
    }
}

angular-animation-looper's People

Contributors

aaron-sterling avatar

Stargazers

 avatar

Watchers

 avatar

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.