Skip to content
Advertisement

How to animate list items in Vue when one is removed

i have a vertical list of items, each of which can be removed. I put my items inside a transition-group and created simple opacity and transform transitions for them. The transitions on the removed elements work as expected, however if I remove an element which is not placed at the bottom, the ones beneath just jump up and take its place without any transition. I Can’t find a way to target this behaviour. All I want is just that the elements below slide up smoothly.

Is there any way to achieve this effect by using css transitipms and Vue’s animation hooks?

Here is a demo: https://jsfiddle.net/gcp18nq0/

Template:

JavaScript

Script:

JavaScript

CSS

JavaScript

The only working way I found was by adding position:absolute on “player-leave-active” state but since the element collapses it changes its vertical position, which is not the desired effect. I also tried changing the height but there the elements below still jump up a bit after the height is set to 0. Im sure that this can be achieved easily with jQuery but i believe that there should be a way to do it without js.

Thank you in advance!

p.s. its my first post here, so i hope that it was explained clearly enough.

Advertisement

Answer

So I made some small tweaks to your fiddle: https://jsfiddle.net/gcp18nq0/1/ and hopefully that is what you looking for.

The most important change was setting display: inline-block on the .panel class, according to the Vue documentation:

One important note is that these FLIP transitions do not work with elements set to display: inline. As an alternative, you can use display: inline-block or place elements in a flex context.

JavaScript
JavaScript
JavaScript
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement