美文网首页
17.vue中多个元素或者多个组件的过渡动画列表过渡

17.vue中多个元素或者多个组件的过渡动画列表过渡

作者: yaoyao妖妖 | 来源:发表于2018-07-07 21:44 被阅读4次

1.多个元素过渡动画

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>vvue中Js动画与Velocity.js库结合</title>
    <script src="./vue.js"> </script>
    <style>
        .v-enter,.v-leave-to{
            opacity: 0;
        }

        .v-enter-active,v-leave-active{
            transition:opacity 1s;
        }
    </style>

</head>
<body>


   <div id="root">
        <!-- mode="in-out"多个元素先进入在隐藏 -->
       <transition mode="in-out"> 
        <!-- dom的复用会让动画不在出现,所以加上key值动画出现 -->
            <div v-if="show" key="hello">hello</div>
            <div v-else ey="Bye World">Bye World</div>
       </transition>  
       <button @click="handleClick">toggle</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>

2.多个组件的过渡动画

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>vvue中Js动画与Velocity.js库结合</title>
    <script src="./vue.js"> </script>
    <style>
        .v-enter,.v-leave-to{
            opacity: 0;
        }

        .v-enter-active,v-leave-active{
            transition:opacity 1s;
        }
    </style>

</head>
<body>


   <div id="root">
        <!-- mode="in-out"多个元素先进入在隐藏 -->
       <transition mode="in-out"> 
           <component :is="type">

           </component>
            <!-- <child-one v-if="show">hello</child-one>
            <child-two v-else>Bye World</child-two> -->
       </transition>  
       <button @click="handleClick">toggle</button>

   </div>

   <script>  

       Vue.component('child-one',{
          
           template:'<div>child-one</div> '
        })

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

           }

       })

   </script>

</body>

</html>

3.vue中的列表过渡

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>vue中的列表过渡</title>
    <script src="./vue.js"> </script>
    <style>
        .v-enter,.v-leave-to{
            opacity: 0;
        }

        .v-enter-active,v-leave-active{
            transition:opacity 1s;
        }
    </style>

</head>
<body>


   <div id="root">
       <!-- 相当于在列表每一层添加transition动画 -->
       <transition-group>
            <div v-for="(item,index) of list" :key="item.id">{{item.title}}</div>  
       </transition-group>

       <button @click="handleClick">add</button>   

   </div>

   <script>  

       var count = 0;
       var app = new Vue({
           el:'#root',
           data:{
               list:[]
           },
           methods:{
            handleClick:function(){
                 this.list.push({
                     id:count++,
                     title: 'helloWorld'
                 })
            }

           }

       })

   </script>

</body>

</html>

相关文章

网友评论

      本文标题:17.vue中多个元素或者多个组件的过渡动画列表过渡

      本文链接:https://www.haomeiwen.com/subject/ypxnuftx.html