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

Firefox experiencing issues with the onchange event

Here in this block of code, I have two dropdown lists: one for department and the other for section name. Based on the selected department, I dynamically change the options available for the section name dropdown list and then populate the values from both ...

The POST request functions smoothly in Postman, however, encounters an error when executed in node.js

Just recently I began learning about node.js and attempted to send a post request to an external server, specifically Oracle Commmerce Cloud, in order to export some data. Check out this screenshot of the request body from Postman: View Request Body In Pos ...

What is the process of initializing divs in DataTables?

My application has a DataTable installed, but I encountered an error message stating "DataTables warning: Non-table node initialisation (DIV). For more details about this error, please visit http://datatables.net/tn/2". I'm aware that DataTables is d ...

I'm interested in knowing how to switch between two functions using Angular

I have developed a grocery list application where each row contains the name of a food item. The layout includes a left column for items that are not needed and a right column for items that are needed. Currently, I am able to change the state by clicking ...

Eliminating event listeners in Nuxt/Vue application

In my current project on Nuxtjs 2.13, I have a question regarding the removal of event listeners. Is it necessary and how should I go about doing it? I'm not referring to traditional JavaScript methods like addEventListener and removeEventListener. I ...

In my Express Javascript application, I recently encountered a challenge where I needed to export a const outside of another

I am currently working with a file named signupResponse.js const foundRegisterUser = function(err, foundUser){ if(!err){ console.log("No errors encountered") if(!foundUser){ if(req.body.password == req.body. ...

Navigational menu that slides or follows as you scroll

Wondering if anyone knows of a straightforward jQuery or Javascript method to create a navigation sidebar that smoothly moves with the user as they scroll down a page. A good example can be found here: Any suggestions would be greatly welcome. ...

Guide on retrieving information from Spark and showcasing it through Angular

Trying to navigate the world of Spark framework and AngularJS as a beginner, I set out to create a basic REST application. However, I hit a roadblock when it came to retrieving data from the server and displaying it using Angular. My initial task was simp ...

Change the font style of individual characters within a string using CSS or JavaScript, instead of applying it to the entire

Is it feasible to assign a specific font to a particular character? I would like: #test_id{ font-family: "digitalfont"; font-family-of-, : "HelveticaNeue-Light"; } In order to set a font for a comma and a separate font for the rest, do I need to ...

Passing data from child component to parent component using Vue emit

Having some trouble figuring out why this code isn't functioning as expected, despite following the same examples I've seen. Parent.vue <tree-select class="ml-5 tree-select" :nodes="all" :value=&q ...

The script fails to start using npm start, however, it runs smoothly when using node server.js

For a while now, I've been facing an issue that I just can't seem to resolve. When I navigate to my project's src folder and execute `node server.js`, everything functions as expected. I can access the application at http://localhost:3000/cl ...

What is the best way to ensure that an iframe adjusts its height to fit the content within a tabbed container?

Is there a way to dynamically set the height of an iframe to match the content inside it when clicking on a tabbed plane? Initially, I used a fixed height of 1000px. How can this be achieved? <div class="container-fluid text-center"> <div ...

How can I dynamically change the className attribute in a Vue v-for loop?

Just starting out with Vue.js and I have a question: I've been attempting this: <li v-for="(msg,index) in system_message" :class="index"> To create different classNames like 0,1,2,3 for each li element. Unfortunately, v-bin ...

Utilizing grease/tampermonkey (or any other browser extension) to filter out specific characters within webpage elements

Forgive me if my language is not accurate, as I am still learning about programming. The forum that I visit has cluttered the page with unnecessary and glitchy images and text for a promotion. This has made the forum difficult to navigate. I was successful ...

ng-bind-html is functional, yet it is raising a TypeError

Below is the code snippet containing the ng-bind-html: <span ng-bind-html="text"></span> Here is the stack trace: angular.js:13236 TypeError: bindings.push is not a function at Function.$$addBindingInfo (http://localhost:9000/bower_component ...

Node Pagination and Filtering feature malfunctioning

I am currently working on incorporating Pagination and Filtering in the backend functionality. This controller receives input such as Page number and Filtering conditions. Controller:- const getPosts = asyncHandler(async (req, res) => { const { ...

Isn't AJAX all about the same origin policy?

Despite my confusion surrounding the same domain origin policy and jQuery AJAX, I have noticed that when I make a GET request to a URL using jQuery, I am able to successfully retrieve the results. This goes against what I understood about the restriction ...

AngularJS - the element of surprise in execution sequence

Encountering a puzzling issue that exclusively affects Internet Explorer (any version) and not Chrome. An "items" array is stored within the "doc" object. Users have the capability to edit items, which essentially deletes the item but retains its content ...

What is the optimal method for assigning a value to a specific key within a JavaScript JSON object?

Below is the information stored in a file called "fokontanys.json": { "vzdveg643": { "lldistrict":"Ambilobe", "id_province": 7, "id": null }, "vzvsdv5327": { "lldistrict ...

Tips for implementing an HTML modal with AngularJS binding for a pop up effect

As a beginner in AngularJS, I am facing a challenge. I have an HTML page that I want to display as a pop-up in another HTML page (both pages have content loaded from controllers). Using the router works fine for moving between pages, but now I want the s ...