zoukankan      html  css  js  c++  java
  • Vue过渡:用Velocity实现JavaScript钩子

    Velocity is an animation engine with a similar API to jQuery's $.animate(). It has no dependencies, but will happily extend jQuery, Zepto, and even the native DOM. It's incredibly fast, and it features color animation, transforms, loops, easings, SVG support, and scrolling.

    一 安装依赖

    npm install velocity-animate  (这里是1.5.2版本)

    文档地址:https://github.com/julianshapiro/velocity/wiki

    二 App.vue

    <!-- App.vue -->
    <template>
      <div id="app">
        <button @click="show = !show">按钮</button>
        <transition 
          @before-enter="beforeEnter"
          @enter="enter"
          @leave="leave"
          :css="false"
        >
          <p v-if="show">芒果</p>
        </transition>
      </div>
    </template>
    
    <script>
    import Vue from "vue";
    import Velocity from "velocity-animate";
    
    export default {
      name: "app",
      data() {
        return {
          show: false
        };
      },
      methods: {
        beforeEnter(el) {
          el.style.opacity = 0;
          el.style.transformOrigin = "left";
        },
        enter(el, done) {
          // 动画队列
          Velocity(el, { opacity: 1, scale: 1.2 }, { duration: 300 });
          Velocity(el, { scale: 1 }, { complete: done });
        },
        leave(el, done) {
          // 动画队列
          Velocity(el, { translateX: "15px", rotateZ: "50deg" }, { duration: 600 });
          Velocity(el, { rotateZ: "100deg" }, { loop: 2 });
          Velocity(
            el,
            {
              rotateZ: "45deg",
              translateY: "30px",
              translateX: "30px",
              opacity: 0
            },
            { complete: done }
          );
        }
      }
    };
    </script>
    
    <style>
    </style>

    三 运行效果

  • 相关阅读:
    Vue模板
    一个人的旅行
    o2o家庭助手demo
    学习html5 app项目开发
    我最近的一段时间技术总结
    我最近的工作、生活状态
    swift学习初步(四)-- 函数
    swift学习初步(三)--控制流操作
    swift学习(二)--基本运算符、字符串、集合操作
    Swift学习初步(一)
  • 原文地址:https://www.cnblogs.com/sea-breeze/p/11310111.html
Copyright © 2011-2022 走看看