JSFiddle - React, Tailwind, and code Playground
by kurotanshi
HTML
<script src="https://unpkg.com/vue@next"></script>
<div id="app">
<button @click="shuffle">shuffle</button>
<transition-group tag="ul"
class="number-list" name="list">
<li v-for="(item, index) in list" :key="item" class="item">{{ item }}</li>
</transition-group>
</div>
SCSS
#app {
position: relative;
display: block;
padding: 1rem;
font-size: 1rem;
}
button {
font-size: 1rem;
margin-bottom: 1rem;
margin-right: 1rem;
}
.number-list {
overflow: hidden;
padding: 0;
margin-bottom: 1.5rem;
> li {
display: inline-block;
width: 35px;
height: 35px;
text-align: center;
line-height: 35px;
background-color: #f00;
color: #fff;
margin-right: 1rem;
margin-bottom: 1rem;
transition: all 0.75s;
}
}
.list-leave-active {
position: absolute;
}
.list-enter-from {
opacity: 0;
transform: translateY(-20px);
}
.list-leave-to {
opacity: 0;
transform: translateY(20px);
}
JavaScript
const app = Vue.createApp({
data() {
return {
list: [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
}
},
methods: {
shuffle() {
this.list.sort(() => Math.random() - 0.5);
}
}
});
app.mount('#app');