Fade transition not working on Vue image element

I have a Vue component that utilizes swiper.js for slide animations. The desired effect is for an image to transition from right to left, expanding from 300x300px to fill the screen, with content such as a title and description overlaying the text.

Currently, I have achieved this by bringing in the image from right to left, allowing it to fill the screen before fading and disappearing. Prior to its disappearance, the component displays a background image which seamlessly transitions into the new slide's image, creating a blended effect with the background. While this process works smoothly in one direction, the issue arises when attempting to rewind the animation. The background image simply flips instantly without recognizing the fade transition applied to that element.

I am seeking assistance to identify any possible errors in my code. Please find the code snippet below where a picture element contains an image that should be updated with a fading effect. Moving forward appears to work as intended since the element is technically hidden, but the transitioning seems ineffective when rewinding.

<template>
  <div class="c-screen">
    <!-- Insert HTML elements here -->
  </div>
</template>

<script>
// Import necessary components

export default {
    data() {
        return {
            backgroundUrl: '/dist/images/icons.svg#icon-connect'
        }
    },
    props: {
        // Define props here
    },
    components: {
        // Declare components used in the template
    },
    computed: {
        // Compute properties here
    }
}
</script>

If additional information is needed, please do not hesitate to ask. Despite searching for a solution, I am unable to pinpoint the exact cause of the issue. Both the picture and img elements have a display block and a set height of 100%.

Thank you in advance for your help.

Answer №1

Utilizing special transition classes in CSS is the key to making it work seamlessly (as stated in the Vue docs). When dealing with a picture element, ensure that you also define CSS rules for any nested img elements. Take a look at the code snippet below:

new Vue({
  el: '#app',
  data: {
    images: [
      "https://images.unsplash.com/photo-1643865420039-0c4d77d0553f?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=870&q=80",
      "https://images.unsplash.com/photo-1643967377110-c17a5ddf14f4?ixlib=rb-1.2.1&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=870&q=80"
    ],
    currentSlide: 0
  },
  mounted: function () {
    setInterval(() => {
      this.currentSlide++
      if (this.currentSlide === this.images.length) {
        this.currentSlide = 0
      }
    }, 4000);
  }
})
.slide-fade-enter-active {
  transition: all 2s ease;
}

.slide-fade-enter-active img {
  transition: all 2s ease;
}

.slide-fade-leave-active {
  transition: all 2s ease;
}

.slide-fade-leave-active img {
  transition: all 2s ease;
}

.slide-fade-enter, .slide-fade-leave-to {
  opacity: 0;
}

.slide-fade-enter img, .slide-fade-leave-to img {
  filter: blur(10px);
  transform: scale(1.2) rotate(3deg);
}

.slider-wrapper {
  position: relative;
  width: 640px;
  height: 400px;
  overflow: hidden;
}

.slider-wrapper img {
  position: absolute;
  top: 0;
  width: 100%;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/vue/2.5.17/vue.js"></script>
<div id="app">
  <div class="slider-wrapper">
    <transition name="slide-fade" mode="in-out">
      <template v-for="(image, index) in images">
        <picture :key="`slide${index}`" alt="" v-if="currentSlide === index">
          <img :src="image" alt="">
        </picture>
      </template>
    </transition>
  </div>
</div>

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

Vue components fail to display properly when transitioning between routes in Vue (version 3) using the Vue Router

Just diving into VueJS version 3 and vue-router. Despite my efforts to troubleshoot by consulting Stack Overflow and Google, the issue remains unresolved. I have defined two routes: /login /admin/index The Problem: While the login route ...

Synk: the presence of a self-signed certificate within the certificate chain

Recently, I've been encountering the error message Synk Protect is showing "self-signed certificate in certificate chain" when I try to run npm install on a project of mine. Would appreciate any help or tips on how to identify which out of the 984 pac ...

The Quirks of jQuery's .load() Method

On my website, I am incorporating a basic jQuery script to load content from one part of a webpage into the 'display container' on the same page. The content being loaded consists of multiple divs enclosed within an outer <div> that is hid ...

Is it possible to time a page without relying on the Form tag?

As I search for solutions, I have come across some examples that require a Form tag, but unfortunately, it doesn't seem to integrate well with my current application. My goal is to implement a timer on a webpage that starts counting when one button i ...

Using JSTL tags may result in returning null or empty values when making Javascript calls or populating HTML

This strange error is puzzling because it appears on some of the webpages I create, but not on others, even though the elements are exactly the same. For instance, this issue does not occur: <main:uiInputBox onDarkBG="${hasDarkBG}" name="quest ...

Ways to verify if TypeScript declaration files successfully compile with local JavaScript library

I have recently updated the typescript definitions in HunterLarco/twitter-v2, which now follows this structure: package.json src/ twitter.js twitter.d.ts Credentials.js Credentials.d.ts My goal is to verify that the .js files correspond correctly ...

The metallic material in Substance Painter appears as a dark shade in A-Frame

After exporting an object as gltf from Substance Painter, I am importing it into my A-frame scene. Strangely, the metallic outer material appears dark in my current scene while other materials like plastic appear white and are visible. Despite already ha ...

Once the data is retrieved and the old image is deleted, attempting to upload the new image still results in the old image being displayed in the Next.js application with React Query

async function fetchTour() { const response = await api.get(`/tour/${router.query.slug}`); return response.data; } const { data: tourData, isLoading, isFetching, isTourError: isError, } = useQuery(['fetchTour', router.que ...

Effortlessly executing POST actions in Yii2 Advanced Template REST API

Hey there! I'm facing a challenge that I need some help with. I am currently working on integrating an API into my Yii2 advanced template to allow my WordPress website to send data to my Yii2 app. Here is the setup of my system: 1) Yii2 advanced templ ...

The dropdown in MaterializeCSS does not display any data retrieved from VUE

Good evening. I am currently utilizing VUE along with MaterializeCSS. I have been trying to populate a selection menu without success. Although I am receiving the data from the database correctly, the options in the select tag remain blank when using V-F ...

Tips for uploading multiple files using django-rest-framework

When trying to upload files using django-rest-frame, I encountered an issue where only the last file uploaded would be saved. How can I ensure that all files are saved? Software versions: Python 3.6.2 Django 2.2.3 djangorestframework 3.10.1 Code snippet: ...

The CSRF token in Laravel Blade seems to be unreachable by Vue

Having a blade with the following code snippet. <meta name="csrf-token" content="{{ csrf_token() }}"> <covid-form> </covid-form> Inside the covid-form component, there is a form structure like this: <form @submit.prevent="send"&g ...

I am encountering challenges with React.js implemented in Typescript

Currently, I'm grappling with a challenge while establishing a design system in ReactJS utilizing TypeScript. The issue at hand pertains to correctly passing and returning types for my components. To address this, here are the steps I've taken so ...

Analyze Javascript code and monitor every variable alongside their corresponding values

After watching Bret Victor's engaging talk "Inventing on Principle" the other night, I was inspired to create a real-time JavaScript editor similar to the one he showcased. You can see a glimpse of it in action at 18:05 when he demonstrates binary sea ...

Passing props to component elements through slots in Vue.js

Trying to pass props from a component element that includes a slot PatientBooking.vue <user-profile :titlename="BOOKINGDETAIL"> <div class="block"> <div>Ereferral: 84884jjd</div> <div>Gender: Mal ...

A step-by-step guide on how to fetch data by id using Vue.js and Laravel

One of my challenges involves managing a database table named candidate_profiles which consists of various columns such as 'user_id', 'photo_id', 'resume_id', 'video_one_id', 'video_two_id', 'video_thr ...

Icon bar struggling to contain voluminous material card content

I've incorporated Material UI cards into my project and have an icon bar at the bottom of each card. However, the media within the card is overflowing onto the icon bar, causing a layout issue as illustrated in this screenshot: https://i.sstatic.net/ ...

When using $resource.save, it returns a "Resource" instead of just an ID

For some reason, I am struggling with a seemingly simple task and cannot find a solution by going through documentation or other Angular related questions on SO. I may not be the brightest, so I could really use some help here as I am feeling stuck. Take ...

The Highcharts plugin is currently not able to render the data

I have been extracting data from the mtgox api and after analyzing my console, I can confirm that all the data is being properly delivered to my chart. Nevertheless, I am facing difficulties in getting the data to actually display on my chart. Any assist ...

Execute React program within VM Azure

After setting up my React application on Azure's virtual machine, I encountered an issue. When trying to access the public URL (DNS) of the VM, I received a "site can't be reached" message. This is the process I followed to launch my project on ...