What could be the reason for the malfunctioning transition effect in my slider animation?

Having trouble getting my slider animation to work. I've tried different CSS styles but the slide transition is not functioning as expected. When one of the buttons is clicked, I want the slide to change from right to left or left to right. Can anyone point out what might be wrong? Check it out here

 <template>
 <div class="sliderComponent">
     <transition-group  name="slide" tag="div" >
         <div v-for="(item, id ) in items" :key="id">
             <img :src="currentImage" title="image" :alt="item.id" class="slideImage">
         </div>
     </transition-group>
     <div class="controls">
         <button class="prev" @click="prevSlide">d</button>
         <button class="next" @click="nextSlide">b</button>
     </div>
 </div>
 </template>
  ______________
 <style>
 .slideImage {
 position: absolute;
 width: 100%;
 height: 100%;
 object-fit: cover;
  }

 .slider-enter-active,
 .slider-leave-active {
 transition: transform 0.5s;
 }

.slider-enter,
.slider-leave-to {
transform: translateX(-100%);
}
 </style>
   

Answer №1

Your current code functionality is outlined as follows:

  • You have an array with image URLs and a current index that points to the current item
  • The current index can be incremented or decremented using buttons, which also occurs in an interval
  • For each item, a div is generated through v-for
  • Each div contains an img element with the same current src
  • All three images are stacked on top of each other via CSS, so only the last one is visible

To incorporate transitions when changing the image, TransitionGroup is suggested. As per the TransitionGroup documentation:

<TransitionGroup> is a built-in component created for animating the insertion, removal, and order change of elements or components rendered in a list.

However, since you're not altering the array, there's no change for TransitionGroup to detect. Instead, utilize a regular Transition:

<transition name="slide" v-for="(src, index) in items">
  <img
    v-if="index === currentSlideIndex"
    :src="src"
  />
</transition>

This setup will only display the current image. When switching images through v-if, the outgoing image transitions out while the incoming image transitions in. Note that the transition class is named .slide-enter-from, rather than just .slide-enter.

Here's a live example

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

Can you please provide guidance on how to dynamically add number values from an array to a select tag in Vue.js?

I'm trying to populate a select tag with options from an array variable that contains arrays of number values. However, the values being output appear to be blank. Here is the HTML code: <select required id="dropDown"> <option>Sele ...

ToggleButtonGroup in Material UI is a great way to create toggle

I am trying to implement the ToggleButtonGroup feature from Material UI in my React application. I am facing an issue where I am unable to pass values into my state correctly. The code snippet provided below shows that while the Select component works fi ...

Error message received while converting webm video to images using Kagami/ffmpeg.js: Unable to locate an appropriate output format for '%04d.jpg'

These are the current versions: node v12.9.1, npm 6.10.2, [email protected] Repository: https://github.com/Kagami/ffmpeg.js The code in decode.js looks like this: const fs = require('fs'); const ffmpeg = require('ffmpeg.js'); c ...

Receiving an error when attempting to utilize a value from the .env file in createSecretKey function

Currently, my code looks like this: const secretKey = crypto.createSecretKey( Buffer.from(process.env.SECRET, "hex") ); However, I am encountering the following error message: "The value of 'key.byteLength' is out of range. It must be > ...

Issue with remove functionality in Vue js implementation causing erratic behavior in my script

Within my Vue.js code, I have a functionality that displays categories from an API. When a category is clicked, it is added to the AddCategory array and then posted to the API. I have also implemented a button called RemoveAll which successfully empties th ...

Properly handling the use of single and double quotation marks in variable declarations within a JavaScript file

I have a search box where users can enter their search text. For example, they can type book, 'book', or "book". The value entered in the search box is then assigned to a variable in the JavaScript file. var searchTerm = "${searchTerm}"; <br/ ...

What steps do I need to take in order to show the present value using a range input?

Hey there! I'm working on a code in HTML that includes an input of type range. Here's what it looks like: This is my input: <input type="range" min="1" max="100" value="50" class="slider" id="myRange"> Unfortunately, I'm unable to s ...

Elegant Decline of Javascript Functionality - Imported Web Assets

Looking for assistance from experienced JS coders. I'm currently working on a Wordpress website that utilizes jQuery AJAX methods to reload either the entire content area or just the main content section based on different navigation clicks. My aim i ...

Remove any errors as soon as the input field becomes valid

My current setup involves AngularJS with node.js. To handle errors, I have devised the following strategy: node router effect.js: router.post('/', function(req, res, next){ req.checkBody('name', 'Eff ...

Experiencing issues with receiving null values in formData when using React hooks

Hello everyone, I am currently experiencing some challenges while utilizing React functional components hooks with formData. The issue I'm facing is that I am receiving null data in formData even though I am using useState hooks. Instead of getting th ...

Learn the technique of coding HTML within inline JavaScript, along with implementing CSS inline styling

I'm looking for a way to incorporate HTML within inline JavaScript, along with CSS inline styles. Can someone provide guidance on how to achieve this? For example, something like the following code snippet: <p><span style="color: #00ff00;"&g ...

Choose all the HTML content that falls within two specific tags

Similar Question: jquery - How to select all content between two tags Let's say there is a sample HTML code as follows: <div> <span> <a>Link</a> </span> <p id="start">Foo</p> <!-- lots of random HTML ...

What is the best way to retrieve the present value of an input that belongs to an array of objects?

Struggling with populating an array with data and encountering a specific issue. 1 - Attempting to determine an index for each key in the array of objects, but encountering an error when a new input is added dynamically. The inputs are successfully added ...

Ways to restrict a JavaScript object from being sent through ajax requests

I have developed an application that utilizes JSON to send messages through ajax. Here is the JavaScript object used for this purpose: var message = { "message_by": colmn[0].innerHTML, "message_date": new Date(), "message_recipients": [ { ...

"JQuery event handlers not functioning as expected: .click and .on failing

For some time now, I've been facing this issue and I'm at a loss trying to figure it out. I have attempted various solutions such as using .click(), .on(), .delegate, and even utilizing .find() to locate the specific element causing the problem. ...

Employing a for loop to verify the existence of a JSON key

Currently, I am attempting to loop through an EJS JSON object and verify the existence of values. If a value does exist, I want to add the corresponding URL to an array further down. Upon loading the page, I am encountering an issue where I am informed th ...

Oops! An unexpected field was encountered while trying to use the uploadMultiple function from dropzone.js

I was looking for a way to allow users to select images to accompany their reviews. That's when I came across dropzone.js. However, I encountered an issue when trying to send multiple images in one request. I expected the req.files to contain an arra ...

Ways to retrieve the parent DIV's width and adjust the child DIV's width to match

Attached is my question with the HTML and a screenshot. Within a DIV container (DIV with ID=ctl00_m_g_a788a965_7ee3_414f_bff9_2a561f8ca37d_ctl00_pnlParentContainer), there are two inner DIVs - one for the left column TITLE (DIV ID=dvTitles) and the other f ...

Modifying the Vuex state triggers automatic updates to the LokiJS database. Wondering why? Discover the connection between Vuex

I am currently facing an issue with my app workflow. It involves retrieving data from an API backend and storing it in client storage using LokiJS, which results in thousands of data entries in client collections. To manage the state of my app, I utilize V ...

Should the use of readFileSync() during the initialization of a Node.js web application be avoided?

I have a Node app that serves web pages with static HTML-snippet files included conditionally. I am considering implementing a cache map for these snippets by adding the following code to my Express's app.js file: var cache = Object.create(null); cac ...