<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Vue中CSS动画原理</title>
<script src="../vue.js"></script>
<style>
.v-leave-to,
.v-enter {
opacity: 0;
}
.v-enter-active,
.v-leave-active {
transition: opacity 3s;
}
</style>
</head>
<body>
<!--
原理: 当一个元素被 transition 包裹了之后,vue会自动的分析一下元素的css样式,构建一个动画的流程
-->
<div id="root">
<transition>
<div v-if="show">Hello world</div>
</transition>
<button @click="handleClick">切换</button>
</div>
<script>
var vm = new Vue({
el: '#root',
data: {
show: true
},
methods: {
handleClick: function () {
this.show = !this.show;
}
}
});
</script>
</body>
</html>