(精华)2020年7月12日 vue 动画transition的使用

自定义动画

<!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>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

愚公搬代码

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值