You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
86 lines
2.2 KiB
86 lines
2.2 KiB
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title>Move Animations</title>
|
|
<style>
|
|
.container {
|
|
position: relative;
|
|
padding: 0;
|
|
}
|
|
.item {
|
|
width: 100%;
|
|
height: 30px;
|
|
background-color: #f3f3f3;
|
|
border: 1px solid #666;
|
|
box-sizing: border-box;
|
|
}
|
|
.fade-move, .fade-enter-active, .fade-leave-active {
|
|
transition: all .5s cubic-bezier(.55,0,.1,1);
|
|
}
|
|
.fade-enter {
|
|
opacity: 0;
|
|
transform: scaleY(0) translate(30px, 0);
|
|
}
|
|
.fade-leave-active {
|
|
position: absolute;
|
|
opacity: 0;
|
|
transform: scaleY(0.01) translate(30px, 0);
|
|
}
|
|
</style>
|
|
<script src="https://cdn.jsdelivr.net/lodash/4.3.0/lodash.min.js"></script>
|
|
<!-- Delete ".min" for console warnings in development -->
|
|
<script src="../../dist/vue.min.js"></script>
|
|
</head>
|
|
<body>
|
|
<div id="el">
|
|
<button @click="insert">insert at random index</button>
|
|
<button @click="reset">reset</button>
|
|
<button @click="shuffle">shuffle</button>
|
|
<transition-group tag="ul" name="fade" class="container">
|
|
<item v-for="item in items"
|
|
class="item"
|
|
:msg="item"
|
|
:key="item"
|
|
@rm="remove(item)">
|
|
</item>
|
|
</transition-group>
|
|
</div>
|
|
|
|
<script>
|
|
var items = [1, 2, 3, 4, 5]
|
|
var id = items.length + 1
|
|
|
|
var vm = new Vue({
|
|
el: '#el',
|
|
data: {
|
|
items: items
|
|
},
|
|
components: {
|
|
item: {
|
|
props: ['msg'],
|
|
template: `<div>{{ msg }} <button @click="$emit('rm')">x</button></div>`
|
|
}
|
|
},
|
|
methods: {
|
|
insert () {
|
|
var i = Math.round(Math.random() * this.items.length)
|
|
this.items.splice(i, 0, id++)
|
|
},
|
|
reset () {
|
|
this.items = [1, 2, 3, 4, 5]
|
|
},
|
|
shuffle () {
|
|
this.items = _.shuffle(this.items)
|
|
},
|
|
remove (item) {
|
|
var i = this.items.indexOf(item)
|
|
if (i > -1) {
|
|
this.items.splice(i, 1)
|
|
}
|
|
}
|
|
}
|
|
})
|
|
</script>
|
|
</body>
|
|
</html>
|
|
|