CSS抛物线组件

Cubic-bezier 曲线

<template>
  <view>
    <view v-if="cart_icon_data != null && (cart_icon_data.status || 0) == 1" class="cart-para-curve-container" :style="cart_icon_data.style">
<!--      <image v-if="(cart_icon_data.icon || null) != null" class="cart-para-curve-icon" :src="cart_icon_data.icon"></image>-->
      <view  class="cart-para-curve-icon cart-para-curve-icon-text"></view>
    </view>
  </view>
</template>
<script>
const app = getApp();
export default {
  data() {
    return {
      cart_icon_data: null
    };
  },
  components: {},
  props: {
    propBtnHeight: {
      type: Number,
      default: 10
    },
    propBtnWidth: {
      type: Number,
      default: 10
    },
    propCart: {
      type: String,
      default: ''
    },
  },
  methods: {
    // 初始(购物车对象、当前点击对象、图标)
    init(cart, pos, icon = '') {
      if((pos || null) != null) {
        var self = this;
        var btn_size = this.propBtnHeight;
        var btn_width = this.propBtnWidth;
        // 未指定购物车对象则读取tabbar数据自动计算购物车位置
        if((cart || null) == null || (cart[0] || null) == null) {
          var info = uni.getSystemInfoSync();
          var tabbar = app.data.tabbar_pages;
          // 无购物车菜单则结束执行
          var tabbar_cart_pos = tabbar.indexOf('/pages/cart/cart');
          if(tabbar_cart_pos == -1) {
            return false;
          }
          // 计算购物车菜单位置
          var tabbar_count = tabbar.length;
          var cart_top = info.screenHeight;
          var cart_width = info.screenWidth/tabbar_count;
          var cart_left = cart_width*tabbar_cart_pos;
        } else {
          var temp = cart[0];
          var cart_width = temp.width;
          var cart_left = temp.left+10;
          var cart_top = temp.top;
        }
        var left = pos.changedTouches[0].clientX + btn_width/2 - btn_size/2-10;
        var top = pos.changedTouches[0].clientY - btn_size;
        var x = cart_left + cart_width/2 - btn_size/2 - left;
        var y = cart_top - btn_size - top;
        if(self.cart_icon_data == null || (self.cart_icon_data.status || 0) == 0) {
          self.cart_icon_data = {
            status: 1,
            style: `--left:${left}px;--top:${top}px;--x:${x}px;--y:${y}px;`,
            icon: icon,
          };
          setTimeout(function(){
            self.cart_icon_data = {status: 0};
          }, 495);
        }
      }
    }
  }
};
</script>
<style>
@keyframes moveY {
  from{
    opacity: 1;
  }
  to {
    opacity: 1;
    transform: translateY(var(--y));
  }
}
@keyframes moveX {
  to {
    transform: translateX(var(--x));
  }
}
.cart-para-curve-container {
  position: fixed;
  width: 60rpx;
  height: 60rpx;
  z-index: 10;
  left: var(--left);
  top: var(--top);
  --duration: 0.4s;
  opacity: 0;
  animation: moveY var(--duration) cubic-bezier(0.5, -0.25, 1, 1);
}
.cart-para-curve-container .cart-para-curve-icon {
  max-width: 100%;
  max-height: 100%;
  animation: moveX var(--duration) linear;
  border-radius: 50px;
  border: 1px solid #eee;
}
.cart-para-curve-icon-text {
  background-color: #f20014;
  display: inline-block;
  padding: 20rpx;
}
</style>

    cartParaCurveEvent(e) {
        let self = this;
        let icon = e.currentTarget.dataset.icon || '';
        uni.createSelectorQuery().select('#cartId').boundingClientRect().exec(function(res) {
          self.$refs.parabolaRef.init(res, e, icon);
        });
    },
<view @click="cartParaCurveEvent"></view>
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

木贝西

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值