question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

`leave` transition doesn't work if the element is shown by default

See original GitHub issue

Vue.js version

1.0.26

Reproduction Link

http://codepen.io/matkovsky/pen/EgYRyV?editors=1010

Steps to reproduce

  1. Create a custom transition.
  2. Add it to an element that has v-show set to true by default.
  3. 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:closed
  • Created 7 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
posvacommented, Feb 8, 2017

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:

leave(element) {
  requestAnimationFrame(() => {
    element.style.height = 0
  })
}

It also works with the solution @liuhao1025 proposed, but using requestAnimationFrame is a more reliable solution

0reactions
posvacommented, Apr 29, 2019

Hey, 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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found