Turn off transition animations

How do I turn off animation in certain cases?

https://jsfiddle.net/4b3nxv7n/

<div id="flip-list-demo" class="demo" :class="{'animate': animate}">
  <button v-on:click="shuffle">Shuffle</button>
  <input type="checkbox" v-model="animate"/>
  <transition-group name="flip-list" tag="ul">
    <li v-for="item in items" :key="item">
      {{ item }}
    </li>
  </transition-group>
</div>

new Vue({
  el: '#flip-list-demo',
  data: {
    animate: true,
    items: [1,2,3,4,5,6,7,8,9]
  },
  methods: {
    shuffle: function () {
      this.items = _.shuffle(this.items)
    }
  }
})

.animate .flip-list-move {
  transition: transform 1s;
}

In this example, I have implemented a modified transition group with a checkbox to control the animation. By using a CSS class, you can disable the animation when needed. However, there is a bug that occurs if you uncheck the checkbox, shuffle the items, and then check it again, the animation may not work properly. It seems that the transition classes are not properly applied in this case.

I also attempted another solution by changing the transition name property, but encountered the same bug: https://jsfiddle.net/61vLtaxn/

<div id="flip-list-demo" class="demo">
  <button v-on:click="shuffle">Shuffle</button>
  <input type="checkbox" v-model="animate"/>
  <transition-group :name="transitionName" tag="ul">
    <li v-for="item in items" :key="item">
      {{ item }}
    </li>
  </transition-group>
</div>
new Vue({
  el: '#flip-list-demo',
  data: {
    animate: true,
    items: [1,2,3,4,5,6,7,8,9]
  },
  computed: {
    transitionName: function () {
        return this.animate ? 'flip-list' : 'disabled-list'
    }
  },
  methods: {
    shuffle: function () {
      this.items = _.shuffle(this.items)
    }
  }
})
.flip-list-move {
  transition: transform 1s;
}

Could this issue be related to a misunderstanding of transitions or possibly a bug in Vue.js?

Answer №1

There is a known bug that has already been reported on the Vue.js GitHub repository, you can find more information here.

To work around this issue, one solution suggested was to include a key attribute within the transition-group component:

<transition-group :name="transitionName" :key="transitionName" tag="ul">

You can also check out this fiddle for reference: Fiddle Link


In my own experience, I discovered a workaround by adding a specific disabled-list-move class (in your second example) with an extremely fast transition (transition: transform 0s resulted in the same problem):

.flip-list-move {
  transition: transform 1s;
}

.disabled-list-move {
  transition: transform 0.0000000001s;
}

Feel free to view this fiddle for demonstration: Fiddle Link

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

The Javascript eval method throws a ReferenceError when the variable is not defined

In my constructor, I was trying to create a dynamic variable from a string. Everything was working smoothly until I suddenly encountered this error out of nowhere. I didn't make any changes that could potentially disrupt the system, and the variables ...

Creating dynamically generated nested text inputs with individual v-model bindings upon the clicking of a button

As a newcomer to vuejs, I am attempting to create nested textboxes dynamically with the click of a button. For a clearer explanation, please refer to this jsfiddle link: https://jsfiddle.net/avi_02/qLqvbjvx/ Let's use an analogy to grasp the iss ...

What is the best way to send two mongoose find queries to the correct GET route?

I am facing an issue with my app where I have two separate routes using app.get to render "/" and fetch data from two different MongoDB collections using mongoose find{} methods. I also have corresponding post routes that redirect the data entered in forms ...

Vue router displays a white screen instead of content

I have been working on a web application using vue.js for my frontend. I have set up my router, but for some reason, the pages are not rendering. I have double-checked everything and there are no errors in my code. Here is a snippet of what I have: App.vu ...

Organizing an array in JavaScript that includes both version numbers and letters, with each letter representing a specific numerical value

If given an array similar to this one: input = [ "1.1", "1.c", "1.b", "1", "D", "b", "4", "2.1.2", "5.1", "3", & ...

What could be the reason for the email not being displayed in the form?

I am attempting to automatically populate the user's email in a form when a button is clicked, preferably when the page is loaded. However, I am encountering issues with this process. This project is being developed using Google Apps Script. Code.gs ...

Dynamically filling a second dropdown menu according to the selection made in the first dropdown using AJAX and PHP

Help! I'm feeling a bit overwhelmed. Even though this question has been answered multiple times, I still can't figure it out. There must be something so obvious that I am missing. I want the options in the second select input to be populated dyn ...

Import csv file into Google Sheets using basic authentication

Looking to retrieve a CSV from a URL that requires basic authentication. I have come across some code that works, but I am having trouble with parsing the CSV, as well as clearing and setting the cells. There are some bugs in the old code that need fixing ...

Troubleshooting issues with JavaScript events in order to effectively implement popovers

I am facing an issue on a webpage that contains a significant amount of JavaScript. The Twitter bootstrap's popover widget is not functioning as expected. Specifically, when I hover over the icon that should trigger the "popover," nothing happens. I h ...

I possess 9 captivating visuals that gracefully unveil their larger counterparts upon being clicked. Curiously, this enchanting feature seems to encounter a perplexing issue within the realm of web browsing

<style type="text/javascript" src="jquery-1.11.0.min.js"></style> <style type="text/javascript" src="myCode.js"></style> </body> //jquery is within my site directory on my desktop $(document).ready(function(){ //note: $("#ar ...

Vue application experiencing never-ending update cycle following array assignment

Here is the JavaScript code I am working with: const storage = new Vue({ el: '#full-table', delimiters: ['[[', ']]'], data: { events: [], counter: 0, }, methods: { eventCounter: fu ...

Verify the presence of a specific select option using text in jQuery version 1.7

Looking at the following snippet of HTML: <select id="sel"> <option value="0">Option1</option> <option value="1">Option2</option> <option value="2">Option3</option> <option value="3">Option4</option> & ...

"Integration error: specified token_name parameters are invalid." FORTPAY INTEGRATION

I have been following the instructions provided by payfort in their email and referring to the Merchant Page 2.0 documentation for integration with nodejs. Despite sending all the necessary parameters in the request body, I encountered an issue where the T ...

I created some jQuery code that modifies a button when it is hovered over, however, I ended up writing the code individually for each button. What steps can I take to turn it

Is there a way to turn the code for each button on my website into a jQuery function that can be applied to any button? This is how the code currently appears: $(document).ready(function() { $("#linkXML").hover( function() { ...

Trying out a React component that relies on parameters for connection

Having an issue while attempting to test a connected react component that requires a props.params.id in order to call action creators. During the testing process, when checking if the component is connected to the store, an error "Uncaught TypeError: Canno ...

Tips for concealing all items except the currently selected branch when clicking on a menu drop-down

I am seeking a solution to open only one node at a time on click, and remove the 'is-active' class from other items. Currently, there is excessive space taken up after opening multiple menu items. I want to ensure that only one node is open at a ...

Import 3D models and textures from a multipart file into three.js using Collada format

I am facing a challenge with loading Collada and image data stored in a multipart file outputted from an application. My goal is to display the Collada object and its associated images using three.js on the Web. However, I'm unsure if three.js can int ...

How to set up a function to detect column resizing within the Angular UI-

Is there a way to detect when a column is resized in ui-grid? I need to perform an operation after the column has been resized but cannot find any events related to column resizing. Any suggestions on how to achieve this? ...

Determine the data type of a function's parameter

Given that TypeScript is a superset of Javascript and 'Type' is not present in the resulting js files, does this mean manipulating 'type' will not function as intended? Furthermore, are there any alternative approaches to achieve this ...

I am struggling to comprehend the passing of elements from an array to a function's argument

I'm grappling with the concept of a function that I grasp. function forEach(array, action) { for (var i = 0; i< array.length; i++) action(array[i]); } When we use this function, like forEach([1,2,3,4,5], console.log);, it essentially swaps ...