Animations
Animate your UI with:
- CSS transitions and CSS
@keyframes - an element's
animate()method - for content that appears and disappears, Angular's
animate.enterandanimate.leave, or theLynxTransitioncomponent
Choose an approach
Angular's animate.enter and animate.leave work, with CSS classes or with a function of your own: see Enter and leave transitions. Its older @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: useanimate.enterorLynxTransitionfor that. - Only some properties animate.
- Write time values with a unit:
0ms, not0. Lynx ignores a bare0.
Keep a transition moving while your app works
Lynx works out each frame of an animation itself, on the thread your Angular code runs on. So a frame Angular spends building a screen is a frame nothing moves.
Put enable-new-animator="false" on an element to hand its transitions and @keyframes to the platform instead:
- iOS uses Core Animation, which keeps them moving whatever the app is doing.
- Android uses its animators.
Add flatten="false" too: Android only animates a transform on an element with a view of its own.
- The element's
animate()method does nothing then: move it withtransitionand@keyframes. - On iOS,
transform,opacityandbackground-coloranimate, and the element's position and size, though its background and children take the new size at once: move it withtransformandopacity. - Start the transition with
afterFrame()after work such as building a screen. iOS begins it at the time of the last frame the app saw, so one started straight after a busy moment is partway through when it's first drawn. <lynx-stack-outlet>moves its screens this way, and the Bottom Sheet its sheet. The Spinner, Skeleton and indeterminate Progress run their loops on the platform too, so they keep going while a screen builds, which is when they show.- The web preview ignores the attribute: the browser runs the transition.
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.- A loop that shows while the app works, such as a spinner, stops while Angular is busy unless the platform runs it: give its element
enable-new-animator="false"andflatten="false"(see above). Arotate()from0degto360degturns there too.
Animate from code
Call animate() on an element you get with viewChild():
Animate from code covers the options and how to pause or cancel.
Enter and leave
Give an element in an @if or @for Angular's animate.enter and animate.leave classes. See Enter and leave transitions.
Or 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 with LynxTransition.
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.
