使用第三方类库实现动画
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>vue动画</title>
<script src="https://cdn.staticfile.org/vue/2.2.2/vue.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.7.2/animate.min.css">
<style>
.my-eneter,
.my-leave-to{
opacity: 0;
transform: tanslateX(100px)
}
.my-enter-active,
.my-leave-active{
transition: all 0.8s ease;
}
</style>
</head>
<body>
<div id="app">
<input type="button" value="toggle" v-on:click="flag = !flag">
<transition enter-active-class="animated bounceIn" leave-active-class="animated bounceOut" name="my">
<h3 v-if="flag">这是一个H3</h3>
</transition>
<!-- 使用:duration来统一设置入场和离场时候的动画时长 -->
<transition enter-active-class="bounceIn" leave-active-class="bounceOut" :duration="400" name="my">
<h3 v-if="flag" class="animated">这是一个H3</h3>
</transition>
<!-- 使用:duration = {enter:200, leave: 400}来分别设置入场时候的动画时长和离场时候的动画时长 -->
<transition enter-active-class="bounceIn" leave-active-class="bounceOut" :duration="{enter:200, leave: 400}"
name="my">
<h3 v-if="flag" class="animated">这是一个H3</h3>
</transition>
</div>
<script>
var vm = new Vue({
el: "#app",
data: {
flag: false
}
})
</script>
</body>
</html>
网友评论