What is causing the collapsed-animation to malfunction in Vue3?

Why won't the transition animation function in vue3js? The animation does not appear to be working for me. I've implemented this library https://github.com/ivanvermeyen/vue-collapse-transition

<template>
  <nav class="navbar color-dark section-padding">
    <span :class="this.$route.meta.connect ? 'navbar-toggler' : ''">
      <button class="border-0 navbar" @click="open()">
        <img :src="navgridImg" style="height: 26px; margin: 1vw" />
      </button>
    </span>

    <CollapseTransition >
      <div v-show="show" :class="showClass" id="navbarSupportedContent">
        jdlkajdlsajdlsjdlskajdlsakjdlsajjdlkajd
        lsajdlsjdlskajdlsakjdlsajjdlkajdlsajdlsjdlska
        jdlsakjdlsajjdlkajdlsajdlsjdlskajdlsakj
        dlsajjdlkajdlsajdlsjdlskajdlsakjdlsaj
      </div>
    </CollapseTransition>
  </nav>
</template>
<script>
  import { ref } from 'vue'
  
  import { CollapseTransition } from "vue-collapse-transition"

  export default {
    components: { CollapseTransition,  },
    setup() {
      const show = ref(false)
      const showClass = ref('collapse navbar-collapse')

      const open = () => {
        show.value = !show.value
      }

      return {
        show,

I have followed the documentation closely and my implementation is quite similar, but the animation is still not functioning as expected. I cannot figure out what might be causing this issue.

Answer №1

@ivanv/vue-collapse-transition is designed for Vue 2 and is not compatible with Vue 3. You can check the version on the NPM page by visiting: https://www.npmjs.com/package/@ivanv/vue-collapse-transition

For Vue 3 transitions, I suggest exploring the built-in options available here: https://vuejs.org/guide/built-ins/transition.html

You don't necessarily need a separate dependency just for a collapse animation ;) Below is an example of a collapse animation using Vue 3 transition features.

<template>
  <button @click="openClose">open/close</button>
  <Transition name="collapse">
    <div class="collapsableDiv" v-if="isShow">
      Lorem ipsum dolor sit amet, consectetur adipiscing elit. In convallis
      blandit congue. Etiam id porttitor eros. Interdum et malesuada fames ac
      ante ipsum primis in faucibus. Aenean ut convallis dui, vitae vehicula
      lacus. Phasellus id blandit urna. Phasellus molestie ex ut sagittis
      scelerisque. Quisque eleifend dui eu quam tempor, a finibus augue
      scelerisque.
    </div>
  </Transition>
</template>

<script setup>
import { ref } from "vue";
const isShow = ref(false);
const openClose = () => {
  isShow.value = !isShow.value;
};
</script>
<style>
.collapsableDiv {
  background-color: rgb(189, 189, 189);
  overflow: hidden;
  width: 250px;
}
.collapse-enter-active {
  animation: collapse reverse 500ms ease;
}
.collapse-leave-active {
  animation: collapse 500ms ease;
}
@keyframes collapse {
  from {
    max-height: 200px;
  }
  to {
    max-height: 0px;
  }
}
</style>

Update: The animation has been improved by eliminating the dependence on max-height; instead, it now utilizes scaleY(). Additionally, the delay issue during animation reverse caused by significantly higher max-height than the actual element height has been resolved.

<style>
.collapsableDiv {
  background-color: rgb(189, 189, 189);
  width: 250px;
  transform-origin: top;
}
.collapse-enter-active {
  animation: collapse reverse 500ms ease;
}
.collapse-leave-active {
  animation: collapse 500ms ease;
}
@keyframes collapse {
  from {
    transform: scaleY(1);
  }
  to {
    transform: scaleY(0);
  }
}
</style>

Cheers :)

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Superior method to ensure the child element's border overlaps with that of the parent

I am currently working on a project that requires a unique CSS effect: Let me explain exactly what I am trying to achieve: The main element (referred to as the title) has padding and a 2px bottom border. Inside this, there is a child element (known as ti ...

What is the best way to add a centered progress spinner on top of an overlay?

Here is a code snippet that includes functionality to append a site overlay as needed. I am currently trying to implement the feature of also displaying an image progress spinner in the center of the screen over the overlay. I would prefer if this spinner ...

Issue with white spaces in footer content in Chrome browser

Currently in the process of developing a website and encountering a strange bug that only seems to be affecting Chrome. Despite having the latest version of Chrome, it appears to be an issue that was prevalent in older versions (v18 - v20). The problem is ...

Guide on dragging and dropping without losing the item, allowing for continuous drag and drop functionality

function allowDrop(ev) { ev.preventDefault(); } function drag(ev) { ev.dataTransfer.setData("text", ev.target.id); } function drop(ev) { ev.preventDefault(); var data = ev.dataTransfer.getData("text"); ev.target.appendChild(document.getElementB ...

Tips for keeping a div fixed at a specific scroll level

Is there a way to keep a specific side div fixed at a particular scroll level, similar to the "How to format" bar on the right side of the Stack Overflow ask question page? You can see it when you try asking a question. How can this be achieved - with CS ...

Div that scrolls independently without affecting the position of other elements

Visit this link for reference <div class="col-10 content" id="content"> <ul> <li>News</li> <li>News</li> <li>News</li> <li>News</li> < ...

Adjust the width of a div in Angular 6 based on a specified condition

I need to adjust the width of a div based on certain conditions. <div [ngStyle]="'width': selectedTab =='Home' ? '50%' : '100%'"> </div> The currently selected tab is stored in "selectedTab". There ...

Utilize CSS to prioritize the image and ensure it is responsive

I'm utilizing the 'featurette' feature in bootstrap. Currently, the page displays text on the left and an image on the right. As you reduce the browser size, they stack on top of each other, with the text appearing above the image. How can I ...

Prevent elements from overlapping within a flexbox container

I've encountered an issue with resizing the window causing the logos to overlap the portrait image. Is there a way to fix the logos relative to the portrait? Below is the code: /* Defaults for Main Part of Pages */ body, div, h1, p { margin: 0; ...

Prevent parent from scrolling when hovering over a div in HTML5

Unfortunately, the scrolling attribute is not supported in HTML5. I'm facing an issue where I have an svg inside an iframe within a div, and I need to enable scroll functionality within the div while preventing the page from scrolling at the same time ...

Enhance User Experience with a Responsive Website Dropdown Menu

Currently, I am focused on enhancing the responsiveness of my website and I realized that having a well-designed menu for mobile view is essential. To address this need, I added a button that only appears when the screen size is 480px or lower, which seems ...

One way to target a span inside a label element when a checkbox is checked using React Material UI createStyles is by using CSS selectors in combination with

I need help targeting the span element within a checkbox label in order to change its background color when the checkbox is checked. <div className={classes.container}> <input type="checkbox" id="checkboxid" /> <lab ...

How come the picture extends beyond the borders of its parent container when I expand the width?

Despite my efforts, I haven't been able to figure this out successfully. My goal is to align the text elements next to the image just like in the example picture below. Initially, I achieved this using absolute positioning. absolute positioning Howe ...

Difficulty with Bootstrap 4 mobile navbar dropdown feature

<div class="baslik baslik1 baslik2 "> <nav class="navbar bg-light navbar-light navbar-expand-sm sticky-top "> <a href="./index.html" class="navbar-brand"><img src="img/512x512logo.png" ...

Direct your attention towards the FormKit component

Seeking to set focus on the initial element within a FormKit form. I attempted to achieve this by referencing and focusing on it upon mount, but encountered an issue. Here is my unsuccessful code snippet: <script setup> import { ref, onMounted } from ...

Creating a dynamic animation effect on a div with a changing number of child elements

Currently, I am utilizing the nganimate library and have implemented an animation that affects the max-height property of a div. Here is a snippet of my code: CSS .sublist.ng-hide { max-height: 0; } .sublist { max-height: 1300px; overflow: hidden; ...

How can I modify the content within a scoped `<style>` tag in Vue?

Is there a way to dynamically change the contents of a <style> block in my Vue component using Vue variables? Many commonly suggested solutions involve inline styles or accessing the .style property with JavaScript. However, I am looking for a metho ...

The callback function fails to execute the click event following the .load() method

Hey there, I've hit a roadblock and could really use some help figuring out where I went wrong. Let me break down my script for you. On page1.html, I have a div that gets replaced by another div from page2.html using jQuery's .load() method. Here ...

How to style a div for printing using CSS

Currently, I am working on a project that has already been completed but now requires some enhancements. To give you an overview, the project includes a search functionality that displays additional details upon clicking on the displayed name in the result ...

How can I showcase Bootstrap cards horizontally within a razor foreach iteration?

I seem to be experiencing a mental block on how to arrange bootstrap cards in a horizontal layout using a for each loop. By default, they appear vertically. Below is my razor code: @foreach (var item in Model) { var imgUrl = Url.Content("~/Conte ...