When I click rapidly, you can see how much more responsive the Spring feels. It can change its direction mid-animation naturally, and so it feels a lot more responsive and alive. We've covered some of the basic Spring animations with toggle, and now let's talk about one of the most powerful features of motion, which is layout animations. They allow us to animate changes in size, position, or order without any manual calculation.
For example, we have this tabs component here, and I would love to animate this indication so that it moves when I switch between the tabs. If I were to do it in JavaScript, I would need to measure the width of each tab, calculate its position, animate between them, handle window resizes and font resizes, so it would have been quite a lot of work. But with motion, it's really easy. We just replace what you have here, like a basic setup of tabs with Redix, and absolutely positioned indicator.
We just need to replace our span with the span from motion, and then we can apply to it layout ID. This works similarly to the view transitions, so motion will actually track this element and automatically animate it between its different positions and sizes. And now, just with this change, when I switch the tabs, you can see that our indicator animates between different states. Though, if you do look closely, you can see there's a little glitch happening with the border radius. This happens because motion uses CSS transforms under the hood to create the animation, which sometimes introduces certain quirks, and border radius is a very common one.
Comments