zoukankan      html  css  js  c++  java
  • Vue2.0的动画效果

    本文只是结合一些代码和图片加强对Vue动画的理解,更多资料请戳这里

    结合原生CSS实现动画

    下面是一张图片,简单清晰明了是吧^-^

    下面是一段代码

    <!DOCTYPE html>
    <html>
      <head>
        <meta charset="UTF-8">
        <title></title>
        <style>
            .show-enter-active,.show-leave-active{
                transition: all 0.4s ease;
                padding-left: 10px;
            }
            .show-enter,.show-leave-active{
                padding-left: 100px;
            }
        </style>
        <script src="https://cdn.jsdelivr.net/npm/vue"></script>
      </head>
      <body>
        <div id="app">
            <button @click="toggle">点击隐藏和显示</button>
          <transition name="show">
              <h3 v-show="isshow">{{message}}</h3>
          </transition>
        </div>
    
        <script>
          new Vue({
            el: '#app',
            data: {
              message:"hello Vue!",
              isshow:false
            },
            methods:{
                toggle:function(){
                    this.isshow = !this.isshow;
                }
            }
          })
        </script>
      </body>
    </html>

    结合animate.css实现动画

    <!DOCTYPE html>
    <html>
      <head>
        <meta charset="UTF-8">
        <title></title>
        <link rel="stylesheet" href="http://apps.bdimg.com/libs/animate.css/3.1.0/animate.min.css" />
        <style>
            .show{
                transition: all 0.4s ease;
            }
        </style>
        <script src="https://cdn.jsdelivr.net/npm/vue"></script>
      </head>
      <body>
        <div id="app">
            <button @click="toggle">点击隐藏和显示</button>
          <transition enter-active-class="fadeInRight"
                      leave-active-class="fadeOutRight">
              <div v-show="isshow" class="animated" class="show">{{message}}</div>
          </transition>
        </div>
    
        <script>
          new Vue({
            el: '#app',
            data: {
              message:"hello Vue!",
              isshow:false
            },
            methods:{
                toggle:function(){
                    this.isshow = !this.isshow;
                }
            }
          })
        </script>
      </body>
    </html>

    使用钩子函数实现动画效果

    <!DOCTYPE html>
    <html>
      <head>
        <meta charset="UTF-8">
        <title></title>
        <style>
            .show{
                transition: all 0.4s ease;
            }
        </style>
        <script src="https://cdn.jsdelivr.net/npm/vue"></script>
      </head>
      <body>
        <div id="app">
            <button @click="toggle">点击隐藏和显示</button>
                <transition @before-enter="beforeEnter" @enter="enter" @after-enter="afterEnter">
                    <div v-show="isshow" class="show">{{message}}</div>
                </transition>
        </div>
    
        <script>
          new Vue({
            el: '#app',
            data: {
              message:"hello Vue!",
              isshow:false
            },
            methods:{
                toggle:function(){
                    this.isshow = !this.isshow;
                },
                beforeEnter:function(el){
                    //定义当前实现动画的初始位置
                    el.style.transform = "translate(100px,0)";
                },
                enter:function(el,done){
                    //设置一下刷新状态
                    el.offsetWidth;
                    //设置动画的结束位置
                    el.style.transform = "translate(0px,0)";
                    //手动调用一下done方法,由这个方法去决定动画是否结束了
                    //否则动画的消失会有延迟
                    done();
                },
                afterEnter:function(el){
                    //将动画的状态复原设置
                    this.isshow = !this.isshow;
                }
            }
          })
        </script>
      </body>
    </html>
  • 相关阅读:
    Linux 6 修改ssh默认远程端口号
    win7安装镜像注入USB3.0,NVMe驱动
    Spring Cloud(7):Zuul自定义过滤器和接口限流
    Spring Cloud(6):Zuul的基本使用
    Spring Cloud(5):Hystrix的使用
    Spring Cloud(4):Feign的使用
    Spring Cloud(3):Ribbon的使用
    Spring Cloud(2):搭建Eureka
    Spring Cloud(1):微服务简介
    SpringBoot 2.x (15):Actuator监控
  • 原文地址:https://www.cnblogs.com/fengxiongZz/p/8071954.html
Copyright © 2011-2022 走看看