Animations
Animate your UI with CSS transitions, CSS @keyframes, an element's animate() method, or the LynxTransition component for content that appears and disappears.
Choose an approach
Angular's @angular/animations package (trigger(), state(), transition()) isn't supported. Use the approaches on this page instead.
Lynx elements do have an animate() method that looks like the browser's Web Animations API. It's Lynx's own version: it returns a handle with only play(), pause() and cancel(). See Animate from code.
CSS transitions
Put transition on an element, then change a property by toggling a class from a signal:
- The handler only sets a signal, which is always safe in an event handler. Angular updates the class after it returns.
- A
transitionruns when a property changes on an element that's already on screen. It doesn't run when the element first appears: useLynxTransitionfor that. - Only some properties animate.
- Write time values with a unit:
0ms, not0. Lynx ignores a bare0.
CSS @keyframes
Define @keyframes in your component styles, and start the animation by adding a class:
- Adding the
spinningclass starts the animation from its first frame, and removing it stops the animation. infinitein theanimationshorthand loops it. Use a number to play it that many times.
Animate from code
Call animate() on an element you get with viewChild():
The setTimeout is required: start animations after the tap handler returns (see the setTimeout rule). Animate from code covers the options and how to pause or cancel.
Enter and leave
Wrap content in <lynx-transition> to animate it in when show turns true, and out before it's removed:
The fade-enter and fade-leave classes each need a @keyframes animation. See Enter and leave transitions.
What can animate
Both transition and @keyframes animate only these properties:
Any other property, such as border-radius, font-size or letter-spacing, doesn't animate.
