Vue.js css animation
- Vue의 transition 태그를 사용하지 않고 css 애니메이션 주기
- 요소 최소화 애니메이션 구현
- 버튼 눌렀을때 나타나고 닫으면 다시 있던 자리로 사라지기
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
|
<template >
<div class="container-wrap" >
<button type="button" @click="showTable" class="table-btn">테이블 보이기</button>
<appTable v-show="isTableVisible" @click="closeTable" class="table"></appTable>
</div>
</template>
<script>
import appTable from '@/components/appTable'
export default {
name: "Container",
components: {
appTable
},
data() {
return{
isTableVisible: false
}
},
methods: {
showTable (){ //테이블 보이기
this.isTableVisible = true;
},
aniEvent (e) {
let table = document.querySelector('.table')
if(e.target.classList.contains('table-hide')){
table.classList.remove('table-hide')
this.isTableVisible = !this.isTableVisible;
}
},
closeTable () { //테이블 가리기
let table = document.querySelector('.table')
table.classList.add('table-hide')
table.addEventListener('animationend', this.aniEvent)
}
},
destroyed () { //이
let table = document.querySelector('.table')
table.removeEventListener('animationend', this.aniEvent)
}
}
</script>
<style scoped>
.table{
position: absolute;
animation: table-visible 0.5s alternate;
transform-origin: left top;
}
.table-hide{
animation: table-none 0.5s alternate;
}
@keyframes table-visible {
from {
transform: scale(0.5);
opacity: 0;
top: 0;
left: 0;
}
to {
transform: scale(1);
opacity: 1;
}
}
@keyframes table-none {
from {
transform: scale(1);
opacity: 1;
}
to {
top: 0;
left: 0;
transform: scale(0.5);
opacity: 0;
}
}
</style>
| cs |