(精华)2020年7月12日 vue 动画transition的使用
【摘要】
自定义动画
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
...
自定义动画
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>动画</title>
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<style>
p{
width: 300px;
height: 300px;
background-color:red;
}
.test-enter-active,.test-leave-active{
transition:all 2s ease;
}
.test-enter-active{
opacity:1;
width:300px;
height:300px;
}
.test-leave-active{
opacity:0;
width:50px;
height:50px;
}
/* .fade-enter需要放在.fade-enter-active的后面 */
.test-enter{
opacity:0;
width: 10px;
height: 10px;
}
</style>
</head>
<body>
<div id="itapp">
<button @click="flag=!flag">点我</button>
<transition name="test"
@before-enter="beforeEnter"
@enter="enter"
@after-enter="afterEnter"
@before-leave="beforeLeave"
@leave="leave"
@after-leave="afterLeave">
<p v-show="flag"
>动画</p>
</transition>
</div>
<script>
var vm = new Vue({
data(){
return {
flag:false
}
},
el:'#itapp',
methods:{
beforeEnter(){
console.log('动画进入之前');
},
enter(){
console.log('动画进入');
},
afterEnter(el){
console.log('动画进入之后');
el.style.background='blue';
},
beforeLeave(){
console.log('动画离开之前');
},
leave(){
console.log('动画离开');
},
afterLeave(){
console.log('动画离开之后');
}
}
})
</script>
</body>
</html>
css3动画库得引用animate.css的使用
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>动画</title>
<link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/animate.css/3.7.2/animate.min.css">
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<style>
p{
width: 300px;
height: 300px;
background-color:red;
margin:0 auto;
}
</style>
</head>
<body>
<div id="app">
<button @click="flag=!flag">点我</button>
<transition enter-active-class="animated bounceInDown" leave-active-class="animated fadeOut">
<p v-show="flag">动画内容</p>
</transition>
</div>
<script>
var vm=new Vue({
el:'#app',
data:{
flag:false
}
});
</script>
</body>
</html>
动画组的使用
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>多元素动画</title>
<link rel="stylesheet" href="https://cdn.bootcdn.net/ajax/libs/animate.css/3.7.2/animate.min.css">
<script src="https://cdn.jsdelivr.net/npm/vue/dist/vue.js"></script>
<style>
p{
width: 100px;
height: 100px;
background-color:red;
margin:20px auto;
}
</style>
</head>
<body>
<div id="itapp">
<button @click="flag=!flag">点我</button>
<transition-group enter-active-class="animated bounceInLeft" leave-active-class="animated bounceOutRight">
<!-- 内部元素 总是需要 提供唯一的 key 属性值 -->
<p v-show="flag" :key="1">itapp</p>
<p v-show="flag" :key="2">软谋</p>
</transition-group>
</div>
<script>
var vm=new Vue({
el:'#itapp',
data:{
flag:false
}
});
</script>
</body>
</html>
文章来源: codeboy.blog.csdn.net,作者:愚公搬代码,版权归原作者所有,如需转载,请联系作者。
原文链接:codeboy.blog.csdn.net/article/details/107304607
【版权声明】本文为华为云社区用户转载文章,如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱:
cloudbbs@huaweicloud.com
- 点赞
- 收藏
- 关注作者
评论(0)