N
N
nepster-web2021-05-28 14:54:37
Vue.js
nepster-web, 2021-05-28 14:54:37

How to add animation when rendering new data in vue js?

There is a table (on div this is important) of 10 lines. The challenge is to keep it up to date.

The actual implementation is straightforward:


The question is how to make the animation so that it looks like the data is moving from top to bottom?

something like this:
60b0d9b0f3db9898014920.gif

It will not be bad if you recommend another library for vue.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vovash, 2021-05-28
@V0vash


during created, the animation will work for everyone, after updating the data it will be played on the last (top)

.table-td {
  border: solid 1px silver;
  padding: 5px;
  margin: 5px;
  animation: 1s ease-out 0s 1 slideInFromLeft;
}

@keyframes slideInFromLeft {
  0% {
    transform: translateY(-100%);
  }
  100% {
    transform: translateY(0);
  }
}

0
0xD34F, 2021-05-28
@0xD34F Vue.js

use transition-group :

<transition-group name="slide" tag="div" class="table-body">
  <div class="table-tr" v-for="item in items" :key="item.id">
    <div class="table-td">{{ item.id }}</div>
    <div class="table-td">{{ item.user }}</div>
  </div>
</transition-group>

.table-tr {
  transition: 0.5s;
}

.table-body {
  overflow: hidden;
}

.slide-enter-from {
  transform: translateY(-100%);
}
.slide-enter-to {
  transform: translateY(0);
}

https://jsfiddle.net/Lr5qnwtv/1/

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question