Is it possible to replicate Svelte's deferred transitions in Vue.js?

Is there a feature in Vue.js that is comparable to Svelte's in:receive and out:receive? I came across this functionality in the Svelte Tutorial, where it smoothly moves a todo from one list to another. You can check out how it works here: .

I've searched through Vue.js documentation at https://v2.vuejs.org/v2/guide/transitions.html, but couldn't find anything similar. Any suggestions?

Answer №1

It appears that Vue lacks built-in support for the defer transition technique known as cross-fade. However, you can utilize <transition-group> to achieve similar effects.

Below is the implementation in Vue. The crossfade effects are implemented using setTimeout and FLIP techniques.

The fundamental concept involves recording positions for both the sending and receiving elements, and deferring the transition with setTimeout (necessary for utilizing FLIP technique).

Check out the final effects on CodePen.

<!-- Utilize preprocessors with the lang attribute! Example: <template lang="pug"> -->
<template>
  <div id="flip-list-demo" class="demo">
    <button @click="shuffle">shuffle</button>
    <input type="text" @keyup.enter="add" />
    <div style="display: flex; flex-direction: row">
      <transition-group
        @before-enter="beforeEnter"
        @enter="enter"
        @leave="leave"
        name="list"
        tag="div"
      >
        <li
          class="list-item"
          v-for="(item, index) in validList"
          v-bind:key="item.value"
          :ref="item.value"
          @click="goInvalid"
          :data-item="item.value"
        >
          {{ item.value }}
        </li>
      </transition-group>
      <transition-group
        name="list"
        @before-enter="beforeEnter"
        @enter="enter"
        @leave="leave"
        tag="div"
      >
        <li
          :ref="item.value"
          class="list-item"
          v-for="(item, index) in invalidList"
          :key="item.value"
          @click="goValid"
          :data-item="item.value"
        >
          {{ item.value }}
        </li>
      </transition-group>
    </div>
  </div>
</template>

<script>
// JavaScript logic here...
</script>

<style>
.list-item {
  transition: all 500ms;
  border: 1px solid #111111;
  height: 50px;
  width: 100px;
  margin: 10px 10px;
}

.list-leave-active {
  position: absolute;
}
</style>

View the complete code and effects on CodePen.

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

Dates comparison causing Firestore security rules issue

After running the query shown below, I encountered a permission-denied message with an error in the "Monitor rules" tab. const timeNow = useMemo(() => Timestamp.now(), []); const query = query( postRef, where("tags", "array-contai ...

Loading React Components dynamically depending on user input

Looking to dynamically render different Components based on checkbox selections without unnecessary component imports. Using an Array with Component names (using numbers for example) to import each component based on the array values. Considered the foll ...

"An error occurred with the Google chart due to 'null' not being recognized as an object, specifically in relation to the select menu and onchange event

Currently, I have implemented the following Script: <header> <script type="text/javascript" src="http://www.google.com/jsapi"></script> </header> <body> <script type="text/javascript"> google.load("visualization", "1 ...

Cease the cropping function for Cropper.js when it extends beyond the boundaries of

Is there a way to prevent the crop corners from moving once the user drags the cursor out of the image while cropping? I encountered an issue where the cropped corners are displaced from the cursor when the user moves out of the image and then back in, wh ...

Waiting for POST request to be executed once data is inserted

This was a new experience for me; I took a break from working on the project for a while, and suddenly all POST routes stopped functioning. However, the GET routes were still working perfectly fine. After extensive debugging, I discovered that removing the ...

Issue with displaying PDF files on Google Chrome due to a software glitch

Recently, I encountered a puzzling issue on Google Chrome. I am not sure if the error lies with Google or within my code. When I set the div as display: none; and then show it again, the PDF view only shows a grey background. However, if I zoom in or out, ...

How can you ensure that an event is added only once when using mouseover functionality?

One approach involves utilizing an event listener that operates as follows (in pseudo code): canvas.onmousemove = function (e) { checkCollision(e); }; var checkCollision = function(e){ var context = canvas.getContext('2d'); var coordina ...

Viewing full size images in the preview selection zone after selecting a crop circle on reduced large images

Currently, I am integrating the Jcrop jQuery library into my project to enable users to select a round/circular crop area on the images they upload. To see a demo of this functionality, visit their official demo page: However, there seems to be an issue w ...

What is the best way to apply lodash's max function to a jQuery array?

I'm having trouble extracting the maximum number of rows from two tables. My variable maxRows ends up being a tbody jQuery element instead of the actual maximum value. I've experimented with both the pluck syntax and the long form, but both metho ...

Using ng-pattern to validate that a text field does not conclude with a particular term

In this code snippet, I am attempting to prevent a textfield from ending with any of the specified letters in the $scope.pointPattern variable. $scope.pointPattern = /^(?!.*ess|ence|sports|riding?$)/; $scope.error = "not valid"; Upon executio ...

How to dynamically add a form to your website

Looking to dynamically insert a form on a page based on the value selected from a datalist, all without having to reload the entire page. <form action='#' method='get'> <input list="category" name="category"> <da ...

Checking for the winner in a JavaScript tic-tac-toe game

Here is the code snippet for a tic-tac-toe game: $(".square").one("click", function() { if( gameOver == false ) { sq1 = $("#sq1").text(); // captures the value of squares after being clicked. sq2 = $("#sq2").text(); //and so on for all 9 squares } / ...

Building a custom Vuetify extension to enhance core features

I am currently working on developing a plugin-based component library to ensure consistency across various product lines using vuetify. However, when I try to install the library and add the components, I encounter multiple errors related to the dark theme ...

Obtain CSS attributes for utilization in Rails variables and database operations

Whenever I click on multiple divs labeled as scale-up, I am able to acquire the css attribute. Yet, my goal is to save these imported css properties in Rails variables and store them in the database. Ultimately, what I aim for is to retrieve the Css prop ...

Model with no collection involved

Take a look at this Model and View setup. Why is the indicated line not functioning as expected? var app = app || {}; (function () { app.CurrentUserView = Backbone.View.extend({ el: $('.avatar-container'), template: ux.templ ...

Jquery Visualization Chart not displaying

I am struggling to get the jquery visualization to work properly. Although the table and caption appear fine, there is no data showing up in the chart. I've carefully followed the example and searched for any issues, but I can't identify what&apo ...

"The controller's $scope isn't being updated within the DIV following a routing change

My website contains ng-view partials that change based on routing updates in $routeProvider. anmSite.config(function($routeProvider, $locationProvider){ $locationProvider.html5Mode(true); $routeProvider //Home page route .when("/", { temp ...

Example of Node-gallery used in isolation, displaying an error event with the message "ENOENT"

I am currently experiencing an issue with the node-gallery npm module. After installing dependencies inside the /example directory, I attempted to run the app. The result was a localhost:3000/gallery page, but upon the page fully loading, I encountered the ...

Getting Jquery to function effectively on a page loaded using ajax请求

I'm facing an issue with writing jQuery code within a page that is loaded via AJAX. When I try to implement the code on the page requested via AJAX, it doesn't work properly. However, if I remove the AJAX request and load the page directly, the j ...

Whenever the ajax oncomplete event is triggered, Primefaces overrides the functionality of jquery, leading to

I have implemented a plugin for fixed table columns in my Primefaces project. The plugin is somewhat functional, but I am facing some issues. primefaces v6.1 jQuery v1.7.1 It works under the following conditions; p:dataTable with <p:ajax event="page ...