美文网首页
3、Vue中的JS动画与Velocity.js的结合(Vue 中

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

作者: 秋玄语道 | 来源:发表于2018-06-30 11:10 被阅读0次
    <!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>
    

    相关文章

      网友评论

          本文标题:3、Vue中的JS动画与Velocity.js的结合(Vue 中

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