(精华2020年5月6日更新) 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>

你可能感兴趣的:((持续更新)vue基础篇,vue.js)