Start flicker issue in Vue 3 transition

I have created a carousel of divs that slide in and out of view on the screen. However, I am facing an issue where during the start of each transition, when a new div is rendered (i.e., the value of carousel_2 changes), it appears without the transition-enter class initially applied to it. This results in the new div flickering over the old one before smoothly transitioning off the screen. It seems like there is a delay in registering that the new div has appeared. If I could somehow postpone the rendering of the new div for a moment, I believe this problem could be resolved. Unfortunately, I am unsure how to achieve this using keys.

<transition name="slide-img">
    <div :key="carousel_2" class="workDiv-container">
        <div class="workDiv">
            <div class="imgDiv">
                <img :src="carousel_2.img" style="width: 100%;"/>
            </div>

            <div class="infoDiv">
                <h1>{{ carousel_2.title }}</h1>
                <h3>{{ carousel_2.creator }}</h3>
                <h3>{{ carousel_2.date }}</h3>
                <h3>{{ carousel_2.medium }}</h3>
                <h3>{{ carousel_2.idno }}</h3>
                <h3>{{ carousel_2.dimensions }}</h3>
            </div>
        </div>
    </div>                                                                   
</transition>

.slide-img-enter {
    left: -100%;
    transform: translate(0, 0);
}
.slide-img-enter-to {
    left: -100%;
    transform: translate(100%, 0);
}
.slide-img-enter-active {
    transition: transform 2s;
}

.slide-img-leave {
    transform: translate(0, 0);
}
.slide-img-leave-to {
    transform: translate(100%, 0);
}
.slide-img-leave-active {
    transition: transform 2s;
}

.workDiv-container {
    position: absolute;
    width: 100%;
    height: 100%;
}

NOTE: The 'carousel_2' variable is recalculated with the object values for display purposes.

Answer №1

At the beginning of each transition, when the new div initially appears (i.e., the carousel_2 key changes), it appears that the transition-enter class is not being applied to it.

Indeed, in Vue 3, the v-enter and v-leave classes have been renamed to v-enter-from and v-leave-from

If you update your transition classes to:

.slide-img-enter-from {
  left: -100%;
  transform: translate(0, 0);
}
/* this one is actually unnecessary */
.slide-img-leave-from {
  transform: translate(0, 0);
}

...the issue should be resolved. See the 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

Blend the power of Node's CommonJS with the versatility of Typescript's ES modules

I currently have a Node.js v10 legacy application that was built using CommonJS modules (require). The entire codebase is written in JavaScript. However, I am considering upgrading the app and refactoring a specific part of it to use TypeScript modules ( ...

The scroll feature in JavaScript is malfunctioning

After countless hours of troubleshooting, I still can't figure out why the code snippet below is not working properly on my website at : <script> $(window).scroll(function () { if ($(window).scrollTop() > 400) { ...

Incorporate a widget with dynamic height adjustment

We are currently working on creating a widget that can be easily embedded by third-party websites. Our goal is to have the widget automatically adjust its height through the embed script. Initially, we considered using an IFrame generated by our JavaScrip ...

When an element in vue.js is selected using focus, it does not trigger re

One of my tasks involves tracking the last selected input in order to append a specific string or variable to it later on. created: function () { document.addEventListener('focusin', this.focusChanged); } focusChanged(event) { if (event ...

Updating an image using AJAX and Flask

I have a situation in HTML where I need to constantly update an image file with the latest images that come in. Below is the Flask code snippet: @app.route('/uploads/update_file', methods=['GET', 'POST']) def update_file(): ...

Angularjs Error Message: Syntax Parsing Issue

Being new to AngularJS, I am trying to grasp the error messages displayed in the console. Below are my JSON object and other details for reference. In the JSP page: <body id="bodyID" ng-controller="ApplicationParameterController" > <div ng-c ...

Design a circular progress bar with a cut-off at the bottom

Does anyone have suggestions on how to create a circular progress bar with cropping at the bottom, similar to this example: PROGRESS BAR? I've been searching for a component like this but haven't had any luck. Any ideas, especially utilizing Mate ...

What is the best way to manage multiple arrays?

There is an array containing multiple arrays within it. I am trying to locate the specific sub-array that contains an object with name: "tax-payer-identification". Once found, I need to set the variable's value from required: true to false. ...

What could be the reason for the inability of my external jQuery file to be implemented on a className within React

I am currently in the process of building a navigation menu for the mobile version of my website using jQuery. However, I'm encountering an issue when trying to integrate it within the className of my reactjs application. Despite placing the jQuery fi ...

Tips for transforming list items into an array of strings

let typeList="[Product,Task,Invoice,Media,Store]"; I need to transform the string above into an array like this:- let typeList=["Product","Task","Invoice","Media","Store"]; Any help with this is greatly appreciated. ...

React - Attempting to access property X from an undefined variable

Trying to access the string in section1.text, but my console is showing: https://i.stack.imgur.com/ox8VD.png Here's the JSX code I'm using: return ( <div> <h1>{this.props.article.title}</h1> ...

Having trouble with uploading files through axios in VueJS 2 and Strapi

Here is the code snippet for my interface: Apply.vue: <template> <div> <div class="send-background"> <form action=""> <div class="send-form-child"> <h3>{{jobin ...

How can I optimize my .find query for a MongoDB GET request to achieve maximum performance?

I'm struggling to figure out how to retrieve only the last item stored in my database using a GET request. While I can successfully get the desired output in the mongo shell (as shown below), I haven't been able to replicate it in my GET route qu ...

Ion-content - Consisting of three elements with varying vertical positioning

I've been facing a challenge trying to include 3 different components (such as buttons, images, etc.) with distinct vertical alignment within the same ion-view. One should be aligned at the top, one in the middle, and one at the bottom. Take a look a ...

Having trouble with importing a TypeScript class: encountering a "cannot resolve" error message

Could you lend me your expertise? I'm puzzled by this issue that seems to be quite simple and straightforward: export class Rectangle { height: number = 0 width: number = 0 constructor(height: number, width: number) { this. ...

The data in Next.js getStaticProps does not update or refresh as expected

As I recently transitioned to working with Next.js, I have encountered several challenges. One issue that arose was related to the use of useEffect in React compared to its behavior in Next.js. In my index file, I have implemented the following code: impo ...

Whenever the page is refreshed, the props in my application are dynamically updated thanks to the getStaticProps function I utilize

Currently, I am in the process of learning nextjs as a beginner. Through the utilization of the getStaticProps function, I have come to understand that data fetching occurs only once at build time and the values remain static thereafter. Despite this, I ...

Vue.js parent component not receiving data emitted by child component

Below you will find the child and parent components. I am struggling to pass data from the child component to the parent component. Can you help me pinpoint where the issue may be? Child Component <template> <div> <v-btn class="r ...

Why is the value in my React Redux state not updating as expected?

I recently started learning react js as a beginner. To practice, I created a crud app and integrated firebase for authentication. However, I'm facing an issue where I'm not able to retrieve the updated value. Index.jsx At line 11, I'm stru ...

Different styles of Unicode arrowheads found on different versions of Android devices

Here is the HTML/CSS code I'm using to create a "Play" button with an arrowhead symbol. The code utilizes ▶ and &9658; to achieve this functionality. <div class='audio-container'> <p style="text-indent:0em;"> <aud ...