Animation
Animate an element from code with animate(), or animate content in and out with <lynx-transition> and <lynx-transition-group>. import { LynxAnimation, LynxTransition, LynxTransitionGroup, type LynxAnimationOptions, type BaseLynxAnimation } from '@blotch/angular-lynx';
Usage
API
animate()
A method on every element's nativeElement, which you get from viewChild() or an ElementRef. It starts the animation at once. A number for options is shorthand for { duration }.
- From an event handler, call it inside
setTimeout. See thesetTimeoutrule. - On the background thread, it returns an animation whose methods do nothing.
- Removing the element cancels its running animations.
LynxAnimation
What animate() returns on the main thread. Don't construct it yourself.
LynxAnimation.id
A unique ID that AngularLynx generates for the animation.
LynxAnimation.play()
Resumes a paused animation.
LynxAnimation.pause()
Pauses the animation at its current frame.
LynxAnimation.cancel()
Stops the animation and removes its effect.
LynxTransition
Mounts its projected content when show turns true, and unmounts it duration milliseconds after show turns false. Meanwhile it adds a class to the <lynx-transition> element itself: {name}-enter on enter and {name}-leave on leave.
- Use CSS
@keyframes, nottransition, in those classes. The class is applied in the same render that mounts the content, so there's no earlier frame to transition from. - Match
durationto your CSS animation's length. Completion is timed, not read from the animation. - The first render doesn't animate. Content that starts visible appears without an enter animation.
LynxTransitionGroup
Renders a list from a child <ng-template let-item> and animates items as they're added and removed. It puts {name}-enter or {name}-leave on each item's root element.
- The first render doesn't animate. Only later changes to
eachdo. - Removed items stay in place while they leave, and the others reorder around them.
- An item that comes back while leaving keeps its view and loses the leave class.
Types
LynxAnimationOptions
AnimationOptions comes from @lynx-js/types. Together they accept:
BaseLynxAnimation
What animate() returns on either thread: an id plus play(), pause() and cancel(). Animation comes from @lynx-js/types.
Related
- Animations: CSS transitions and keyframes.
- Animate from code
- Enter and leave transitions
- Threads
