14.vue中的CSS动画原理

2154922-38a6950cbb6c3193.PNG
IMG_1636.PNG
2154922-a5a0ec1ac7ddbc0d.PNG
IMG_1637.PNG
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>vue中的CSS动画原理</title>
    <script src="./vue.js"> </script>
    <style>

        /* 相同动作的可以写到一起   过渡动画效果 */
        /* 动画开始时存在,但是第二帧就移除了,opacity从0变成了1 默认是v-enter*/
        .fade-enter{
            opacity: 0;

        }
        /* 动画开始时存在,动画结束时移除,监听到这种变化之后,就开始动画了 默认是v-enter-active*/
        .fade-enter-active{
            transition: opacity 3s;
            
        }

        /* 动画开始时不存在,但是第二帧增加,动画结束后移除,opacity从1变成了0 默认是v-leave-to*/
        .fade-leave-to{
            opacity: 0;
        }        
               
        /* 动画开始时存在,动画结束时移除,监听到这种变化之后,就开始动画了 默认是.v-leave-active*/
        .fade-leave-active{
            transition: opacity 3s;
        }

    </style>
</head>
<body>


   <div id="root">
       <transition name="fade">
            <!-- <div v-show="show">hello</div> 效果相同,动态组件也带这个动态效果-->
            <div v-if="show">hello</div>
       </transition>  
       <button @click="handleClick">切换</button>

 
   </div>

   <script>  

       Vue.component('child-one',{
          
           template:'<div>child-one</div> '
        })
 
       var app = new Vue({
           el:'#root',
           data:{
            show :true
           },
           methods:{
            handleClick:function(){
                this.show = !this.show

            }
           }

       })

   </script>

</body>

</html>

猜你喜欢

转载自blog.csdn.net/weixin_33892359/article/details/87636435
今日推荐