朴朴超市加入购物车动画-贝塞尔曲线

<template>
  <div class="container">
    <div v-for="(item, index) in dataList" :key="index" class="item-container">
      <div class="animationIcon">
        <div
          v-for="animation in animations"
          :key="animation.id"
          :class="{'baltRight': index % 2 === 0, 'balt': index % 2 !== 0}"
          v-if="animation.active && animationIndex === index"
        >
          <div :class="{'innerRight': index % 2 === 0, 'inner': index % 2 !== 0}"></div>
        </div>
      </div>

      <div class="button-container">
        <button
          class="roundBtn"
          :class="buttonClass(item)"
          @animationend="resetAnimation"
          @click="decrease(index)"
        >
          <span :class="{ rotate: item.num === 0 }">-</span>
        </button>
        <span v-if="item.num > 0">{{ item.num }}</span>
        <button class="roundBtn" @click="increase(index)">
          <span :class="{ rotate: item.num > 0 }">+</span>
        </button>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      dataList: [{ num: 1 }, { num: 12 }, { num: 13 }],
      animationIndex: null,
      animations: []
    };
  },
  methods: {
    buttonClass(item) {
      if (item.num === 0) {
        return "hidden";
      } else {
        return "visible-in";
      }
    },
    increase(index) {
      this.dataList[index].num++;
      this.animationIndex = index;
      const animation = {
        id: Date.now(),
        active: true
      };
      this.animations.push(animation);

      setTimeout(() => {
        animation.active = false;
        setTimeout(() => {
          this.animations = this.animations.filter(anim => anim.id !== animation.id);
        }, 1000);
      }, 1000);
    },
    decrease(index) {
      if (this.dataList[index].num > 0) {
        this.dataList[index].num--;
      }
    },
    resetAnimation() {
      // 处理动画结束后的逻辑
    }
  }
};
</script>

<style lang="scss">
.container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.item-container {
  margin-bottom: 10px;
}

.button-container {
  position: relative;
  height: 50px;
  width: 50px;
}

.roundBtn {
  border-radius: 50%;
  width: 50px;
  height: 50px;
  font-size: 24px;
  transition: transform 0.5s;
  position: absolute;
  top: -7px;
  left: 31px;
  line-height: 51px;
}

.roundBtn span {
  display: inline-block;
  transition: transform 0.5s;
}

.rotate {
  transform: rotate(90deg);
}

.hidden {
  opacity: 0;
  transition: transform 0.5s, opacity 0.5s;
}

.visible-out,
.visible-in {
  transform: translateX(-100px);
  transition: transform 0.5s;
}

.animationIcon {
  position: relative;
  top: 0;
  left: 0;
  background: red;
}

.balt,
.baltRight {
  position: absolute;
  width: 25px;
  height: 25px;
  border-radius: 50%;
  z-index: 99999;
}

.inner,
.innerRight {
  background: red;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  z-index: 99999;
}

.balt {
  animation: moveX 1s 1;
}

.inner {
  animation: moveY 1s cubic-bezier(1, -1, 1, 10) 1;
}

.baltRight {
  animation: moveXR 1s 1;
}

.innerRight {
  animation: moveYR 1s cubic-bezier(1, -1, 1, 10) 1;
}

@keyframes moveX {
  50% {
    transform: translateX(-100px);
  }

  100% {
    transform: translateX(-100px);
  }
}

@keyframes moveY {
  50% {
    transform: translateY(1000px);
  }

  100% {
    transform: translateY(1000px);
  }
}

@keyframes moveXR {
  50% {
    transform: translateX(180px);
  }

  100% {
    transform: translateX(180px);
  }
}

@keyframes moveYR {
  50% {
    transform: translateY(1000px);
  }

  100% {
    transform: translateY(1000px);
  }
}
</style>

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值