Full docs can be found at nickgraffis.github.io/ng-spring
yarn add ng-spring
Or use npm
or pnpm
.
Useage is extreamly simple, just replace keyframes
from @angular/animations
with the default export from ng-spring
.
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
}
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
}
Default: 100
The attraction force of a spring. Higher values create faster, sharper movement.
Default: 10
The opposing force of a spring. Higher values reduce the bounciness of the spring.
Default: 0.001
The precision of values that are being animated.
Default: 'px'
The unit of measurement for the css properties.