JSFiddle - React, Tailwind, and code Playground
by lid0
HTML
<div id="app">
<div id="list-complete-demo" class="demo">
<button @click="shuffle">Shuffle</button>
<button @click="add">Add</button>
<button @click="remove">Remove</button>
<transition-group class="test" name="list-complete" tag="div">
<span :ref="idx.toString()" v-for="item,idx in items" :key="item" class="list-complete-item inner-test">
{{ item }}
</span>
</transition-group>
</div>
</div>
CSS
body {
margin: 30px;
}
button {
margin-right: 10px;
}
.list-complete-item {
transition: all 0.8s ease;
display: inline-block;
margin-right: 10px;
}
.list-complete-enter-from,
.list-complete-leave-to {
opacity: 0;
transform: translateY(30px);
}
.list-complete-leave-active {
position: absolute;
}
.test {
display: grid;
grid-template-columns: repeat(5, 5fr);
position:relative;
}
.inner-test {
background-color: red;
border: solid 2px black;
}
JavaScript
import {createApp,defineComponent,provide, inject,ref} from "https://unpkg.com/[email protected]/dist/vue.esm-browser.js";
const Demo = {
data() {
return {
items: [1, 2, 3, 4, 5, 6, 7, 8, 9],
nextNum: 10
}
},
methods: {
randomIndex() {
return Math.floor(Math.random() * this.items.length)
},
add() {
this.items.splice(this.randomIndex(), 0, this.nextNum++)
},
remove() {
var idx = this.randomIndex();
this.$refs[idx].style.width= this.$refs[idx].clientWidth + "px"
this.items.splice(idx, 1)
},
shuffle() {
this.items = _.shuffle(this.items)
}
}
};
createApp(Demo).mount("#list-complete-demo");