功能:给宽高为100px的正方形添加入场和退场效果
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>transition</title>
<script src="../vue1/vue.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/4.1.1/animate.min.css" />
<style>
.box {
width: 100px;
height: 100px;
background-color: red;
}
/*入场前*/
.fade-enter {
/*可以看到的物体的大小 --> scale范围[0,1]*/
transform: scale(0);
}
/*入场时*/
.fade-enter-active {
/*整个过程持续的事件*/
transition: all 2s;
}
/*入场后*/
.fade-enter-to {
transform: scale(1);
}
/*退场前*/
.fade-leave {
transform: scale(1);
}
/*退场时*/
.fade-leave-active {
transition: all 2s;
}
/*退场后*/
.fade-leave-to {
transform: scale(0);
}
</style>
</head>
<body>
<div id="main">
<button @click="show=!show">show</button>
<transition name="fade">
<div class="box" v-if="show"></div>
</transition>
</div>
<script>
new Vue({
el: '#main',
data() {
return {
show: false,
}
}
})
</script>
</body>
</html>