美文网首页
19vue-transition元素过渡

19vue-transition元素过渡

作者: 滔滔逐浪 | 来源:发表于2021-08-08 16:33 被阅读0次
    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="utf-8">
            <title></title>
            <script src="../../lib/vue.js"></script>
            <script src="../../lib/axios.js"></script>
        </head>
        <style>
            .kerwin-enter-active {
              animation: aaa 1.5s;
            }
        
            .kerwin-leave-active {
              animation: aaa 1.5s reverse;
            }
        
            @keyframes aaa {
              0% {
                opacity: 0;
                transform: translateX(100px);
              }
        
              100% {
                opacity: 1;
                transform: translateX(0px);
              }
            }
          </style>
        <body>
            <!-- <div class="kerwin-enter-active">111</div> -->
            <div id="app">
                 <button @click="isShow=!isShow"> click</button>
                 <transition name="kerwin" mode="in-out">
                     <div  v-show="isShow">
                      <div v-if="isShow" key="111">111</div>
                       <div v-else key="222">222222</div></div>
                 </transition>
                
            </div>
    
    <script>
        
        new Vue({
            el:"#app",
            data:{
                isShow:false
                
            }
            
        });
    </script>
        </body>
    </html>
    
    

    transition-group

    <!DOCTYPE html>
    <html>
        <head>
            <meta charset="utf-8">
            <title></title>
            <script src="../../lib/vue.js"></script>
            <script src="../../lib/axios.js"></script>
        </head>
        
            <style>
                 .kerwin-enter-active {
                  animation: aaa .5s;
                }
        
                .kerwin-leave-active {
                  animation: aaa .5s reverse;
                }
        
                @keyframes aaa {
                  0% {
                    opacity: 0;
                    transform: translateX(100px);
                  }
        
                  100% {
                    opacity: 1;
                    transform: translateX(0px);
                  }
                }
            </style>
        <body>
            <div id="app">
                <input type="text" v-model="mytext">
                <button @click="handleclick()">add</button>
                
                    <div v-if="datalist.length===0">空空</div>
                    <ul v-else>
                        <transition-group name="kerwin">
                        <li v-for="(data,index) in datalist" :key="data">
                            {{data}}
                            <button @click="handleDel(index)">del</button>
                        </li>
                            </transition-group>
                        </ul>
            
            </div>
    
    <script>
        
        new Vue({
            el:"#app",
            data:{
            datalist:[] ,
            mytext:""
                
            },
            methods:{
                handleDel(index){
                    this.datalist.splice(index,1);
                },
                handleclick(){
                    this.datalist.push(this.mytext);
                       //重置input
                                        this.mytext=""
                }
            }
            
        });
    </script>
        </body>
    </html>
    
    
    
    

    相关文章

      网友评论

          本文标题:19vue-transition元素过渡

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