Giter Site home page Giter Site logo

nickgraffis / ng-spring Goto Github PK

View Code? Open in Web Editor NEW
2.0 1.0 0.0 880 KB

1.8kb function that replaces Angular animation's keyframes with springKeyframes, for physics based animations.

Home Page: https://nickgraffis.github.io/ng-spring

License: MIT License

TypeScript 88.65% JavaScript 11.35%
angular angular-animations animations keyframes physics spring spring-physics spring-keyframes

ng-spring's Introduction

Documentation

Full docs can be found at nickgraffis.github.io/ng-spring

Installation

yarn add ng-spring

Or use npm or pnpm.

Usage

Useage is extreamly simple, just replace keyframes from @angular/animations with the default export from ng-spring.

Basic

import springKeyframes from 'ng-spring'

@Component({
  selector: 'app-hello',
  animations: [
    trigger('openClose', [ 
      transition('open => closed', [
        animate('500ms', springKeyframes({
          from: {opacity: 0, transform: 'translateY(-100px)'},
          to: {opacity: 1, transform: 'translateY(0)'}
        }))
      ]),
    ])
  ]
})
export class HelloComponent {
  @HostBinding('@openClose')
  public animate = true
}

It works the same in more advanced use cases:

import springKeyframes from 'ng-spring'

@Component({
  selector: 'app-hello',
  animations: [
    trigger('helloAnimation', [
      transition(':enter', [
        query('.hero', [
          stagger(30, [
            animate('500ms', springKeyframes({
              from: {opacity: 0, transform: 'translateY(-100px)'},
              to: {opacity: 1, transform: 'translateY(0)'}
            }))
          ])
        ])
      ])
    ])
  ]
})
export class HelloComponent {
  @HostBinding('@helloAnimation')
  public animate = true
}

Options

The first option of springKeyframes is an object with two properties, from and to. The from property is an object with the properties that you want to animate from, and the to property is an object with the properties that you want to animate to.

The second option of springKeyframes is the options object.

interface Options {
  stiffness: number
  damping: number
  precision: number
  unit: string
}

Stiffness

Default: 100

The attraction force of a spring. Higher values create faster, sharper movement.

Damping

Default: 10

The opposing force of a spring. Higher values reduce the bounciness of the spring.

Precision

Default: 0.001

The precision of values that are being animated.

Unit

Default: 'px'

The unit of measurement for the css properties.

ng-spring's People

Contributors

nickgraffis avatar

Stargazers

 avatar  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.