-
Notifications
You must be signed in to change notification settings - Fork 303
/
25.动画-列表动画.html
95 lines (89 loc) · 2.69 KB
/
25.动画-列表动画.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<script src="./lib/vue.js"></script>
<style>
li{
border: 1px dashed #999;
margin: 5px;
line-height: 35px;
padding-left: 5px;
font-size: 12px;
width: 100%;
}
.v-enter,
.v-leave-to{
opacity: 0;
transform: translateY(90px)
}
.v-leave-active,
.v-enter-active{
transition: all 0.6s ease;
}
li:hover{
background-color: blue;
transition: 0.5s
}
/*下面的.v-move和.v-leave-active配合使用,能够实现列表后续的元素渐渐的漂上来的效果*/
.v-move{
transition: all 0.6s ease;
}
.v-leave-active{
position: absolute
}
</style>
</head>
<body>
<div id="app">
<div>
<label>
ID:
<input type="text" v-model="id">
</label>
<label>
Name:
<input type="text" v-model="name">
</label>
<input type="button" value="Add" @click="add">
</div>
<!--在实现列表过度的时候,如果需要过渡的元素是用transitionGroup 而不是 transition-->
<!--给transition-group添加apper属性,实现入场时侯的效果-->
<!--通过给transition-group标签tag属性指定将来transition-group渲染成什么元素-->
<transition-group appear tag="ul">
<!--如果要为v-for创建的元素设置动画,必须为每一个元素设置 :key属性-->
<li v-for="(item, i) in list" :key="item.id" @click="del(i)">
{{item.id}} ------------ {{item.name}}
</li>
</transition-group>
</div>
<script>
var vm = new Vue({
el: '#app',
data:{
id:'',
name:'',
list:[
{id:1, name:'Bob'},
{id:2, name:'Trump'},
{id:3, name:'Rechial'},
{id:4, name:'Frank'}
]
},
methods: {
add(){
this.list.push({id:this.id, name:this.name})
this.name=''
this.id=''
},
del(i){
this.list.splice(i,1 )
}
},
})
</script>
</body>
</html>