3、Vue中的JS动画与Velocity.js的结合(Vue 中的动画特效)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Vue中的JS动画</title>
    <script src="js/vue.js"></script>
    <script src="js/velocity.js"></script>
</head>
<body>
  <div id="app">
      <transition
              name="fade"
              @before-enter="handleBeforeEnter"
              @enter="handleEnter"
              @after-enter="handleAfterEnter">
          <div v-show="seen">hello world</div>
      </transition>
      <button @click="handleClick">切换</button>
  </div>
  <script>
      new Vue({
          el:'#app',
          data:{
              seen:true
          },
          methods:{
              handleClick:function () {
                   this.seen=!this.seen
              },
              handleBeforeEnter:function (el) {
                  console.log("ss")
                  el.style.color='red'
              },
              handleEnter:function (el,done) {
                 setTimeout(()=>{
                     el.style.color='blue'
                 },2000)
                  setTimeout(() => {
                     done()
                  },4000)
              },
              handleAfterEnter:function (el) {
                  el.style.color='#000'
              }
          }
      })
  </script>
</body>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Velocity.js的结合</title>
    <script src="js/vue.js"></script>
    <script src="js/velocity.js"></script>
</head>
<body>
  <div id="app">
      <transition
              name="fade"
              @before-enter="handleBeforeEnter"
              @enter="handleEnter"
              @after-enter="handleAfterEnter">
          <div v-show="show">hello world</div>
      </transition>
      <button @click="handleClick">切换</button>
  </div>
  <script>
      new Vue({
          el:'#app',
          data:{
              show:true
          },
          methods:{
              handleClick:function () {
                  this.show=!this.show
              },
              handleBeforeEnter:function (el) {
                  el.style.opacity=0;
              },
              handleEnter:function (el,done) {
                   Velocity(el,{opacity:1}
                   ,{duration:1000,complete:done})
              },
              handleAfterEnter:function (el) {
                  alert("结束动画")
              }
          }
      })
  </script>
</body>
</html>
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容