`leave` transition doesn't work if the element is shown by default
See original GitHub issueVue.js version
1.0.26
Reproduction Link
http://codepen.io/matkovsky/pen/EgYRyV?editors=1010
Steps to reproduce
- Create a custom transition.
- Add it to an element that has
v-show
set to true by default. - Toggle the value of
v-show
(by toggling the corresponding data in the model, of course).
What is Expected?
It should animate.
What is actually happening?
The first leave
is not animated. It looks like the v-leave
([transitionName]-leave
) class is missing the first time.
Issue Analytics
- State:
- Created 7 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
CSS Transition doesn't work with top, bottom, left, right
Try setting a default value for top in the CSS to let it know where you want it to start out before transitioning:...
Read more >Using CSS transitions - CSS: Cascading Style Sheets | MDN
CSS transitions provide a way to control animation speed when changing CSS properties. Instead of having property changes take effect ...
Read more >transition — Alpine.js
The simplest way to achieve a transition using Alpine is by adding x-transition to an element with x-show on it. For example: <div...
Read more >An Interactive Guide to CSS Transitions - Josh W Comeau
When we tell an element to transition from one position to another ... from left to right, these are the frames that were...
Read more >Transitions - web.dev
Using CSS transitions, we can interpolate between the initial state and the target state of the element. The transition between the two enhances...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
After checking it again, this is not a bug. The element has not been rerendered the first time when you set the height on the
beforeLeave
hook, and therefore the CSS transition triggers as if the height is still 0.You need to ensure the height is always set and used before setting the height to 0. You should use requestAnimationFrame in the
leave
hook to make it work properly (the same way you should do it in the leave hook:It also works with the solution @liuhao1025 proposed, but using
requestAnimationFrame
is a more reliable solutionHey, this is a Vue 1 issue. Implementing the CSS collapsing transition is sometimes tricky and varies depending on browsers. There are nice articles out there to implement this like: https://markus.oberlehner.net/blog/transition-to-height-auto-with-vue/
I’m locking this thread as it is outdated