举个自定义动画例子给你看一下,你就明白了。
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title></title>
<style type="text/css">
.content{
width: 200px;
height: 200px;
background: skyblue;
}
.fade-enter-active, .fade-leave-active {
transition: opacity 5s;
}
.fade-enter, .fade-leave-to /* .fade-leave-active below version 2.1.8 */ {
opacity: 0;
}
.slide-enter-active{
transition: all 3s;
}
.slide-leave-active {
transition: all 5s;
}
.slide-enter, .slide-leave-to /* .fade-leave-active below version 2.1.8 */ {
transform: translateX(500px);
opacity: 0;
}
</style>
<script src="js/vue.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<div id="app">
<!--
属性NAME会跟框架追加的类名一致
-->
<transition name="slide">
<div v-if="isShow" class="content"></div>
</transition>
<button @click="toggleEvent">切换内容</button>
</div>
<script type="text/javascript">
let app = new Vue({
el:"#app",
data:{
isShow:true
},
methods:{
toggleEvent:function(){
this.isShow = !this.isShow
}
}
})
</script>
</body>
</html>
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…