simultaneous fading in and out transitions for two distinct elements

I'm a newcomer to Vue.js and the world of transitions. Currently, I'm working on designing a Vue component that will handle lazy loading data from a server. My goal is to display a loading gif when data is not yet available.

Everything seems to be functioning correctly. However, when I attempted to implement a simple fade transition to smoothly switch between displaying the loading gif and rendering the content upon data availability, I encountered an issue. The content and gif seem to push each other up or down while transitioning in and out simultaneously.

Here's a snippet from my Lazy.vue component file:

<template>
  <div class="fixed-pos">
    <transition name="fade">
        <slot v-if="loaded"></slot>
        <div v-else>
            <img src="../assets/loading.gif"/>
        </div>
    </transition>
  </div>
</template>

<script>
export default {
  name: 'Lazy',
  props: {
    loaded: {
      type: Boolean
    }
  }
}
</script>

Additionally, here's how I implemented it in a sample usage:

<template>
  <div>
    <button @click="loaded = !loaded">Toggle</button>
        <lazy :loaded="loaded">
            <ul v-if="rendered">
                <transition-group name="fade">
                    <li v-for="notif in notifs" v-bind:key="notif">
                        <span>{{notif}}</span>
                    </li>
                </transition-group>
            </ul>
        </lazy>
  </div>
</template>

<script>
import Lazy from './Lazy'

export default {
  name: 'HelloWorld',
  components: {
    Lazy
  },
  data () {
    return {
      msg: 'Welcome to Your Vue.js App',
      rendered: true,
      notifs: [
        'Notif 1',
        'Notification 2 is here!',
        'Here comes another notification',
        'And another here ...'
      ],
      loaded: true
    }
  }
}
</script>

Lastly, my animation.css file contains the following:

.fade-enter-active, .fade-leave-active {
  transition: opacity .5s
}
.fade-enter, .fade-leave-to {
  opacity: 0
}

Are there any solutions using Vue transitions or alternative methods to address this issue?

Answer №1

Make sure to include the CSS rule position: absolute; for your gif and content to display correctly: Check out this JSFiddle example.

According to the documentation:

When using position: absolute, no space is reserved for the element in the page layout. It will be positioned relative to its closest ancestor with a defined position, or else it will be placed relative to the initial containing block.

Additionally, consider adding position: relative; to the parent element of the gif and content for proper positioning.

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

Adjust a parameter within a MongoDB array entity

I am attempting to update a value within an array of objects. Looking at the MongoDB schema above, my goal is to find an expense with an ID that matches the _id and update the fields with new values from req.body. Specifically, I need to update expensesTyp ...

Apply a CSS3 Box Shadow to a diagonal corner

Currently, I am exploring some new coding techniques to enhance my skills. I have a slanted left corner design element. Now, I am trying to incorporate a box shadow effect as shown in the following image: https://i.sstatic.net/1MnL2.png This is the code ...

What is the best way to extract a value from a JSON object?

I am having trouble deleting data from both the table and database using multiple select. When I try to delete, it only removes the first row that is selected. To get the necessary ID for the WHERE condition in my SQL query, I used Firebug and found this P ...

Disabling the NavBar occurs when aligning it to the right

When attempting to align my NavBar to the right, I noticed that using float:right caused it to shift to the right but become unresponsive. Take a look here: goo.gl/46yUrt Snippet of Code: /** * 4.2 Navigation * --------------------------------------- ...

Error: Cannot locate 'import-resolver-typescript/lib' in jsconfig.json file

Issue: An error occurred stating that the file '/Users/nish7/Documents/Code/WebDev/HOS/frontend/node_modules/eslint-import-resolver-typescript/lib' could not be found. This error is present in the program because of the specified root file for c ...

Looking for a solution to the issue of updating quantity in a shopping cart with Vue and

https://i.sstatic.net/N2vPN.png Whenever I try to increase or decrease the quantity on my shopping cart checkout page by clicking the + or - buttons, it doesn't update in real-time. However, if I navigate back to the product page and then return to t ...

Is it possible to use Nuxt-link for panning instead of clicking?

Instead of clicking on a nuxt-link to navigate across pages, is it possible to trigger the same action by swiping? I'm curious if I can achieve this functionality using pan gestures instead of traditional link clicks. Something like this (utilizing ha ...

section featuring a striking visual, user input form, and descriptive content

I want to create a layout with a background image in a div, a signup form on the right side, and a div containing h1 tags on the left side. Here is the HTML code: <html> <title> GoToMy PC </title> <head> <link rel="stylesheet" ...

Verifying the presence of a cookie when the page loads

My goal is to have the browser initially check for a cookie named "yes." If this cookie exists, I would like to show a message. If not, I want to display the following: <input type="button" id='approve' value="approve" onclick="a()"/> &l ...

Is it possible to dynamically load a specific div when the page loads, relying on the

I am using JQuery SlideUp and slideDown methods to toggle the visibility of panels. How can I load or display the first record's contact information as a default? Currently, it loads blank because I set the panel's display property to none: < ...

Setting up Npm Sequelize Package Installation

Could use some help with setting up Sequelize. Here's the current status: https://i.sstatic.net/MQH1I.jpg ...

Select the element to emphasize it and reduce the visibility of others

I'm currently facing an issue with a block that contains multiple divs representing products. My goal is to have the selected product highlighted while the rest appear less prominent when clicked. I've managed to achieve this functionality, howev ...

Different ways to activate the system bell in Node.js

Currently, I have a custom nodejs script running for an extended period and I'm seeking a way to receive a notification once the script finishes its execution. Is there a method in nodejs that can be used to activate the "System Bell" alert? ...

Why does the implementation of my interface differ from what is specified in the TypeScript documentation?

Currently delving into the world of TypeScript documentation https://www.typescriptlang.org/docs/handbook/2/classes.html Specifically focusing on the section implements Clauses, an interesting revelation surfaces: A Word of Caution It’s worth noting t ...

Posting data using the form method="post" in Vue does not seem to be working

My goal is to create a website that allows users to reserve a seat using a specific password and time slot. I've set up a form where users can input the password and their name, then submit the form to make the reservation. However, I'm facing an ...

"Utilizing Vue-router to dynamically update meta tags based on route properties

I'm facing an issue with changing the meta attribute in my .vue file. Currently, I am only passing the id property, but I want the name to be set using meta.name. I attempted to implement the solution suggested by Phil (here), but unfortunately, it di ...

The dark mode class in Next.js/React does not take effect until a local change is made

I've been diving into a helpful tutorial on implementing dark mode toggle in my project. The tutorial uses react-toggle and can be found here. Everything seems to be working fine except for one issue that arises on the initial page load. When the bro ...

Accessing packet data details in JavaScript

I am curious about the feasibility of a certain task. Essentially, I am interested in executing JavaScript code on the client side while simultaneously sending an AJAX request to my server to perform specific actions and then receive information back fro ...

Child stateless component in React receiving outdated props from parent Class component

Within my Parent Component, there is a form that users interact with. The form displays real-time information that updates as fields are edited. However, I am encountering an issue where the child component sometimes receives outdated props from the previo ...

Utilizing innerfade plugin for displaying adaptive images on websites

After setting up a responsive design, I incorporated the innerfade plugin to create a carousel of pictures. However, I noticed that as the width of the page changes, the height of the pictures becomes smaller and fails to cover the entire area required. ...