321倒计时

这是一个使用Vue.js编写的组件,名为ThreeSecondsPopup,功能是显示一个从3倒计时到0的弹窗。组件利用数据绑定和定时器实现倒计时效果,同时应用了CSS动画来增强用户体验。当倒计时结束时,会触发一个自定义事件threeSecondsShow,以便在父组件中处理后续操作。
摘要由CSDN通过智能技术生成
<template>
  <view class="popup" >
    <view class="popup_wrapper">
      <view
        class="count"
        v-show="count"
        :class="
          count && count % 2 === 0 ? 'count-animation-0' : 'count-animation-1'
        "
      >
        {{ count }}
      </view>
    </view>
  </view>
</template>

<script>
export default {
  name: 'ThreeSecondsPopup',
  data() {
    return {
      count: '', // 倒计时时间
      timer: null,
    }
  },
  created() {
    this.countDown()
  },
  methods: {
    countDown() {
      const TIME_COUNT = 3
      if (!this.timer) {
        this.count = TIME_COUNT
        this.timer = setInterval(() => {
          if (this.count > 1 && this.count <= TIME_COUNT) {
            // 限制倒计时区间
            this.count--
          } else {
            clearInterval(this.timer) // 删除定时器
            // 三秒后关闭(三秒后需要进行的操作)
            this.$emit('threeSecondsShow', this.ThreeSecondsShow)
          }
        }, 1000)
      }
    },
  },
}
</script>

<style scoped lang="scss">
@import '~@/styles/mixin.scss';
.popup {
  position: fixed;
  bottom: 0;
  left: 0;
  height: 100vh;
  width: 100vw;
  background: $uni-bg-color-mask;
  z-index: 1001;
  .popup_wrapper {
    width: 100%;
    height: 100%;
    @include flex-layout($dir: column, $justify: center, $align: center);
    .count {
      opacity: 0;
      transform: scale(3);
      font-size: 180rpx;
      color: #fff;
      text-shadow: 0rpx 0rpx 20rpx #e2e5e9;
    }

    .count-animation-0 {
      animation: move-0 1s ease-in-out 1;
    }
    .count-animation-1 {
      animation: move-1 1s ease-in-out 1;
    }

    @keyframes move-0 {
      0% {
        opacity: 1;
        transform: scale(3);
      }
      97% {
        opacity: 1;
        transform: scale(1);
      }
      100% {
        opacity: 0;
        transform: scale(1);
      }
    }
   // css3动画
    @keyframes move-1 {
      0% {
        opacity: 1;
        transform: scale(3);
      }
      97% {
        opacity: 1;
        transform: scale(1);
      }
      100% {
        opacity: 0;
        transform: scale(1);
      }
    }
  }
}
</style>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值