I'm trying to replicate this animation from Material.io:
To just navigate the height like the click on the first card in the example above is simple. Just animate height attribute. The problem is with the click on the second card where it then pushes the other cards away.
One solution to this is to use scroll to emulate the effect that things get pushed away. So when you click on the item, it both makes it taller by animating the height, but also scroll the view at the same time.
My problem:
I can't seem to figure out how to animate scrolls with @angular/animations
.
I can't use style({ scrollTop: 100 })
, it only allows for CSS attributes according to the documentation.
How do I achieve this? It would be nice if I could do it as part of the animate()
animation for maintenance reasons (To keep the whole animation in 1 location in the code), but if it's only possible with a separate method I guess that would be acceptable as well.
I managed to create this, using three Angular animations states : small, big and normal, corresponding to the height of the div :
animations.ts
Here, I used one state variable per div as an example, and I set the each of these states to normal by default. Then, depending on which div I click on, I toggle the states according to what we want to happen : making the div we click on bigger and the others smaller
app.component.ts
And here is the corresponding template :
Each div has the reference to the animation trigger
[@expand]
and its state.Here is a StackBlitz example I made for this : https://stackblitz.com/edit/angular-t47iyy