12.vue 点击购物车小球效果解决定位问题:

2019-04-01  本文已影响0人  崩鲨卡拉卡
4.实现点击购物车小球弹入效果:
<transition
         @before-enter="beforeEnter"
         @enter="enter"
         @after-enter="afterEnter"
      >
        <div class="ball" v-show="ball_show" ref="ball" ></div>
      </transition>
data() {
    return {
      ball_show:false,
    };
  },
定义方法
beforeEnter(el){
          el.style.transform = 'translate(0, 0)'
      },
     enter(el,done) {
       const ball=this.$refs.ball.getBoundingClientRect();
       const shopicon=document.getElementById("shopcar").getBoundingClientRect();
       console.log(ball);
       console.log(shopicon);
       let top=shopicon.left-ball.left;
       let bottom=shopicon.top-ball.top;


       el.offsetWidth;
       el.style.transform=`translate( ${top}px,${bottom}px )`;
       el.style.transition='all 1s cubic-bezier(0,.73,.37,1)';
       done();
     },
     afterEnter(el){
        this.ball_show=!this.ball_show;
     }
小球动态效果实现后遇到一下问题:
解决思路:
enter(el,done) {
       const ball=this.$refs.ball.getBoundingClientRect();
       const shopicon=document.getElementById("shopcar").getBoundingClientRect();
       console.log(ball);
       console.log(shopicon);
       let top=shopicon.left-ball.left;
       let bottom=shopicon.top-ball.top;


       el.offsetWidth;
       el.style.transform=`translate( ${top}px,${bottom}px )`;
       el.style.transition='all 1s cubic-bezier(0,.73,.37,1)';
       done();
     },
注意:
小球定位.png
上一篇 下一篇

猜你喜欢

热点阅读