Simultaneous movements within a Vue.js collapsible panel

Struggling with a Vue.JS accordion that has transitions to collapse and expand the sub menus? The issue is that Vue seems to wait for one transition to finish before starting the next, even though all transitions are applied at the same time.

Specifically, the selected accordion tab opens before the currently open tab starts to close.

Below is the template in question:

<ul>
  <li @click="expand('i1')" :class="{'active': expanded.i1}"> Item 1
    <transition name="drop">
      <ul v-if="expanded.i1">
        <li><a href="#">Link 1 </a></li>
        <li><a href="#">Link 2 </a></li>
        <li><a href="#">Link 3 </a></li>
        <li><a href="#">Link 4 </a></li>
      </ul>
    </transition>
  </li>
  <li @click="expand('i2')" :class="{'active': expanded.i2}"> Item 2
    <transition name="drop">
      <ul v-if="expanded.i2">
        <li><a href="#">Link 1 </a></li>
        <li><a href="#">Link 2 </a></li>
        <li><a href="#">Link 3 </a></li>
        <li><a href="#">Link 4 </a></li>
      </ul>
    </transition>
  </li>
</ul>

Here is how I dealt with it using the Vue instance:

new Vue({
  el: '#app',
  template: template,
  data: {
    expanded: {
      i1: true,
      i2: false
    }
  },
  methods: {
    expand(option) {
      for(let i in this.expanded) {
        this.expanded[i] = i === option;
      }
    }
  }
});

Lastly, the transition CSS used:

.drop-enter-active, .drop-leave-active {
    transition: max-height 2s linear;
}

.drop-enter, .drop-leave-to {
    max-height: 0;
}

.drop-leave, .drop-enter-to {
    max-height: 500px;
}

For a visual representation of the problem, check out the CodePen here: https://codepen.io/martiensk/pen/WMRmqB

Answer №1

After some investigation, it became clear that the issue stemmed from my use of max-height for animation. I have since decided to implement a JavaScript solution instead. The codepen has been revised accordingly.

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

Using Vue.js: Sending a Data Object to the Store via an Action

I am looking for a way to send a data object to my Vue store using an action. This is my current approach: <button type="button" name="button" class="btn btn-primary" @click="addToCart(row)">Add to cart</button> ...mapActions(["addToCart"]) ...

Concealing divs without values in ASP.NET MVC

I am working on an AJAX call to fetch data from the back-end and populate divs with it. Below is my code for the AJAX call: $(document).ready(function() { question_block(); }); function question_block() { $.ajax({ url: '@Url.Action(" ...

Customize your webpage's style to reflect your unique identity with user

Is there a way to allow users to customize the style of a webpage? I know I need multiple CSS files, but how can I implement the code that enables this customization based on user preferences? ...

Import divX from page2 into page 1 by utilizing jsonp to circumvent the restrictions of the same origin policy

I've been attempting to load a div from another page with the following code, $('#result').load('page2.php #divX') However, the JavaScript on that page doesn't seem to work, even though both page1 and page2 are linked to the ...

Encountering a Mirage undefined error (no defined route) during testing using Vue and Cypress

I successfully integrated Mirage into my Vue CLI App alongside Cypress to enhance the mocking of my database. Following Mirage's quickstart tutorial, I attempted to rewrite my login test. However, when trying to log in through a POST request to the AP ...

Troubleshooting: Unable to Remove Files in PhoneGap

I've been working on a basic app that heavily utilizes PhoneGap to test its capabilities. Currently, I'm trying to delete a file that has been downloaded within the app, but I'm encountering some issues. The majority of the code I've im ...

Removing a portion of an item with the power of RxJS

I possess the subsequent entity: const myObject = { items:[ { name: 'John', age: 35, children: [ { child: 'Eric', age: 10, sex: 'M' }, { ...

Setting Vuetify component props dynamically depending on certain conditions

I've implemented a navbar component in my web app using the v-app-bar Vuetify component. However, I'm facing an issue where I need to dynamically set the props of the v-app-bar based on the current page the user is viewing. <v-app-bar absolu ...

Can a link be generated that swaps out the original URL redirect for the following visitor upon clicking?

Can the program be fed with a list of links to automatically redirect to the next URL once clicked? In this setup, each visitor would only see one link and not have access to any other URLs in the chain. Is there a way to make this happen? Any suggestion ...

Modifying the background image of div elements with JQuery in a loop function is ineffective when using Google Chrome

I am facing an issue in my application where I have a for loop to change the background image of two divs. The code snippet is as follows: for (var i = 0; i < length; i++) { $("div_" + (i + 1)).css("background-image", "../imageFile.png"); ...

Is it possible to use an angular expression as the ng-click function?

I have been searching everywhere for the answer to this question. Within my code, there is an angular object called column.addOnParams. This object includes a child element named rowClick, which can be accessed using column.addOnParams.rowClick. The val ...

pop-up window that shows chosen choices using javascript or ajax

I have a specific HTML code that allows users to select multiple options. I would like these selected options to be displayed in a popup or a div in real-time as the user makes their selections. I have attempted using a selectbox with checkboxes, but extra ...

"Troubleshooting: Click counter in HTML/Javascript unable to function

My latest HTML project is inspired by the "cookie clicker" game, and I'm working on it for a friend. So far, I've managed to get the click counter to function to some extent. Essentially, when you click on the image, the number at the bottom sho ...

Creating HTML input elements dynamically using Javascript

<body> <form action="insertquestion.php" method="POST"> <script> function generateInputs(){ var prefix = "answer"; var number = 1; for(var i = 0; i < 5; i++){ ...

Unable to destructure the 'reservations' property from 'this.props.reservation' due to its undefined status, implementing a filter in ReactJs

I am having trouble retrieving reservations from my server when I try to access the rooms. I have followed a similar method but for some reason, I can't seem to access them. My goal is to retrieve reservations from the server and filter them based on ...

Tips for refreshing a webpage after switching screens

// I have implemented the code below to navigate from one screen to another, specifically the Home page. However, I am facing issues with the page refreshing or reloading when navigating to the home screen. None of the lifecycle methods are being called, e ...

How can JavaScript pass a variable through the URL?

I am attempting to pass a variable through the URL: http://localhost/new_wiki/test.php?id=http://example.com In my code, I have var first = getUrlVars()["id"];. This line is supposed to pass the value but it doesn't seem to be working. Can someone pl ...

The comments entered into the box are being overridden instead of being posted

I have encountered an issue where, upon hitting the post button, the comment is successfully posted on the page. However, if I hit the button again, it seems to override the previous comment. Can someone please provide clarification on this matter? Additio ...

Creating a smooth transition curve for moving the camera along the z-axis using JavaScript and Three.js技

I am venturing into the world of Three.js and facing a challenge. In the center of my scene, I have a rotating icosahedron. When I click a button, it should start rotating faster and the camera should move closer to make it appear larger. However, I am str ...

Creating an attractive image carousel using jQuery or YUI for your website

I am searching for a javascript-based slideshow solution for images. I have received the following requirements: The slideshow should fade one image into another, looping back to the first image after all images have been displayed It must include naviga ...