Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Fix animation of neighboring elements vue3 transition

I am trying to figure how animate the button movement …

when I check the checkbox, the textarea appears correctly with the transition … and button sort of jumps down (which is fine with me for now)…

But the problem is, that when I uncheck the checkbox, the textarea disappears (within a transtion – all good) but after the transition is finished, the button JUMPS up 🙁 it looks horrible.. how do I fix that?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

<script setup>
import { ref } from "vue";

const showNote = ref(false);
const toggleCheckbox = () => {
  showNote.value = !showNote.value;
};
</script>

<template>
  <div class="add-note">
    <div class="flex align-items-center">
      <input type="checkbox" :checked="showNote" @click="toggleCheckbox"/>
      <label>Show note</label>
    </div>
    <Transition>
      <div v-if="showNote" class="note-area">
        <div class="form-item-full-width">
          <textarea id="w3review" name="w3review" rows="4" cols="50"></textarea>
        </div>
      </div>
    </Transition>
  </div>
  <Transition>
  <div class="form-body">
    <div class="form-item-full-width">
      <button type="button">Submit data</button>
    </div>
  </div>
  </Transition>
</template>


<style>
.v-enter-active,
.v-leave-active {
  transition: opacity 0.5s ease;
}

.v-enter-from,
.v-leave-to {
  opacity: 0;
}
</style>

here is an example in playground

>Solution :

In addition to avoid the "jump up" behavior, what you need to do is transitioning the max-heigth of the text area :

<style>
  .v-enter-active,
  .v-leave-active {
    transition: all 0.5s ease;
    max-height: 100px;
  }

  .v-enter-from,
  .v-leave-to {
    opacity: 0;
    max-height: 0px;
  }
</style>

See your example updated : Vue SFC Playground

Note: in this update I also remove the Transition tags wrapping the "Submit" button.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading