What is the method for animating the appearance of v-for items individually?

If I want to showcase a group of elements appearing one by one instead of all at once, I can achieve this by wrapping a v-for loop in a transition-group. Here's how:

<script setup>
import {onMounted, reactive} from "vue";

const state = reactive({
    hover: false,
    fadeInArray: [false, false, false, false, false]
})

onMounted(() => {

    let val = 0;
    setInterval(() => {
        state.fadeInArray[val] = true
        val++
        if (val == state.fadeInArray.length) {
            clearInterval()
       }
    }, 2000)

})

</script>


<template>
      <transition-group name="fade-1">
        <div class="partner-wrap" v-for="(partner, key) in [1,2,3,4,5]" :key="key">
          <p v-if="state.fadeInArray[key]">I am fading in!</p>
         </div>
      </transition-group>
</template>

Even though the transition may not be working as expected and the elements seem to pop in without animation. Consider checking the provided transition scss:

.fade-1 {
  &-enter-active, &-leave-active {
    transition: all 1s;
  }

  &-enter-from, &-leave-to {
    opacity: 0;
  }
}

Answer №1

It seems that the second example is not functioning correctly primarily because the v-if is placed on an element that is not a direct child of transition-group

In the comments, I pointed to the Vue 3 documentation's example on Staggering List Transitions, which I still believe is one way to tackle this issue.

This explanation details how to animate elements of the parent v-for after they are created, but my requirement involves animating them while they are being created.

Not entirely accurate. The tutorial showcases how to animate "appear"/"leave" elements when the content of the rendered array changes (via filter). To implement the animation of elements appearing after the initial rendering of the component, you just need to have the rendered array empty upon mounting the component and then enable the items after a short delay post-mount.

The provided code snippet from the example achieves precisely that:

const mounted = ref(false)

onMounted(() => setTimeout(() => mounted.value = true, 200))

const computedList = computed(() => {
  return list.filter((item) => item.msg.toLowerCase().includes(query.value) && mounted.value)
})

Demo

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

Revising Data in JavaScript Tables

I'm facing an issue with a 2D array, cells, which stores cellData values. There's a JavaScript function called displayTable that I use to present this array as a table. The problem arises when clicking on a cell – its cellType is supposed to ch ...

Exploring ways to efficiently test the nested promises in an Angular service function

Here is a snippet of what my service implementation looks like: TestService.initializeDefaults = function() { var qPromise = $q.defer(); $q.all({ localResource: localResource.fetch(), item: itemResource.fetch() }).then(functio ...

Tips for creating animations using parent and child components in Angular

Despite my best efforts, it seems like this should be functioning properly... but unfortunately it's not... I'm attempting to achieve a transition effect on the parent element (ui-switch-groove) while the child element (ui-switch-dongle) moves. ...

Maintaining accurate type-hinting with Typescript's external modules

Before I ask my question, I want to mention that I am utilizing Intellij IDEA. In reference to this inquiry: How do you prevent naming conflicts when external typescript modules do not have a module name? Imagine I have two Rectangle classes in different ...

Choose according to reactjs using react-select

Currently working on a ReactJS app that includes a page with two select elements, where one is dependent on the other. I am integrating react-select and @material-ui. Within the context of dates: [ { "id": 1, "name": "20 ...

Tips for utilizing playFromPositionAsync method with expo-av Video in React Native

While working with the Video Expo component, I came across a prop called playFromPositionAsync. In the Video.d.ts file, it is defined like this: export default class Video extends React.Component<VideoProps, VideoState> implements Playback { ... ...

Node.js - creating dynamic routes using Express parameters

Despite things functioning partially, I'm encountering an issue where the user_id is not being passed into the URL correctly. Instead of the actual user_id, I am only seeing ":user_id" as a literal string like this: Below is the snippet from my users ...

Looking to include a button at the bottom with the lowest possible index value

<button class="btn" onclick="addNewButton(0)" value="">123</button> <button class="btn" onclick="addNewButton(1)" value="">456</button> <button class="btn" onc ...

Having trouble interacting with the "Continue" button on PayPal while using Selenium

Recently, I have encountered an issue with automating payments via PayPal Sandbox. Everything used to work smoothly, but now I am unable to click the final Continue button no matter what method I try. I have attempted regular clicks, using the Actions cl ...

Making an Ajax Request to Retrieve Data from Multiple URLs

Currently, I am attempting to perform an ajax call using the following URL: . The page number in the URL needs to be dynamic based on the response received from this ajax call. Here is my current code snippet: $.when( $.get("http://exampleurl ...

My Next.js app's iframe is being blocked by Chrome. Any suggestions on how to resolve this issue?

I have encountered an issue while trying to display an iframe in my Next.js application. Although the iframe is functioning properly in Firefox, it is being blocked in Chrome. The process of rendering the iframe seems straightforward. Below is the comple ...

Running JavaScript within Objective-C in a Cordova plugin

I'm working with cordova version 6.5.0 and I'm trying to develop a plugin that can execute some javascript code. I've read on various forums that I can use stringByEvaluatingJavascriptFromString method in my webview, but it seems like it&ap ...

How can I display a drilldown label in HighCharts on a mobile device?

When viewing the chart on mobile devices, I notice that the drilldown data label for my pie chart is being truncated with ellipses. My goal is to adjust the styles so that the entire word "streaming" is displayed without any dots cutting off the bottom par ...

What is the reason that property spreading is effective within Grid components but not in FormControl components?

Explore the sandbox environment here: https://codesandbox.io/s/agitated-ardinghelli-fnoj15?file=/src/temp4.tsx:0-1206. import { FormControl, FormControlProps, Grid, GridProps } from "@mui/material"; interface ICustomControlProps { gridProps?: ...

Combining Laravel and Javascript to store quantities and IDs in a nested array structure

I am currently facing an issue with saving all the product_id's along with their respective quantities in a multidimensional array. In my Laravel project, I am using a foreach loop to iterate over each product within a larger products array. Each pr ...

Troubleshooting my nodejs websocket chat for message sending glitches

The chat system is built on nodejs using websockets from socket.io library. While I have a client that also utilizes websockets from socket.io, I'm facing challenges in making the two communicate effectively. The issue seems to be with the client not ...

Issue with TableHead not functioning properly when sorting is requested

I'm currently facing an issue with my table that has clickable row headers for sorting functionality using the onRequestSort function. Unfortunately, it seems like this feature is not working as expected. I have implemented the sorting logic using rea ...

I'm noticing my table collapsing as I move around the div elements - any idea why this is happening

A challenge I am facing is creating a dynamic table where users can drag and drop colored boxes with animated transitions. While it mostly works well, sometimes the table collapses inexplicably. Here are steps to reproduce the issue: Move 100 - 400 Move 1 ...

Obtain an array containing only the specific values of each object

Currently, I have the following code snippet: <db.collection>.find({ id : { $exists: true } }) This query retrieves all documents containing an id property. However, I am interested in transforming this result into an array that contains only the va ...

Fade Toggle fails to toggle properly

QUESTION: What could be the reason behind my fade in/fade out not functioning as expected? How can this issue be resolved effectively? BACKGROUND STORY: Upon clicking a link, a javascript/jQuery event is meant to display or hide a series of LI's. Pre ...