微信小程序实现拼团成功动画

本文介绍了如何在微信小程序中实现拼团成功后的动画效果,包括头像飞入的动态展示。通过使用两个组件——整体组件PinTuan和头像组件PinTuanHead,分别详细说明了各组件的js、json、wxml和wxss代码实现。
摘要由CSDN通过智能技术生成

 

微信小程序实现如上效果。

分为两个组件:

  • PinTuan: 整体组件
  • PinTuanHead: 每个头像组件

代码如下:

PinTuan.js

Component({
  attached:function() {
    // 获取头像地址数据,返回一个头像地址数组
    notification.addObserver('你自己的消息事件', (config) => {
      this._getServeHeadData(config);
    }, this);
  },

  detached: function() {
    this._stopInterval();
    this._stopTimeOut();
  },

  ready: function() {
    // 初始化适配rpx
    this._initRpx();
  },
  
  /**
   * 组件的属性列表
   */
  properties: {

  },

  /**
   * 组件的初始数据
   */
  data: {
    personNum: 1,
    successedImg: 'XXX.png',
    joinText: "即将成团",
    clockText: "00:00:00",  // 倒计时文字初始值
    headsArr: [],  // 所有头像url地址库
    headUrls: [],  // 头像url数组
    moveHead: '',  // 头像飞动图片
    headAniData: {},  // 头像动画animation
    successAni: {},  // 成功动画animation
    pinTuanAni: {},  // 拼团整体上滚刷新animation
    headAniOrigin: true,  // 头像飞动动画是否归位
    successAniOrigin: true,  // 成功动画是否归位
    pinTuanAniOrigin: true,  // 拼团组件动画是否归位
    pinTuanSuccess: false,  // 拼团成功图标显示
    countDownSeedTimer: 10,  // 倒计时最小随机数,也是拼团成功最大时间随机数
    pinTuanMinSeedTimer: 3,  // 拼团最小随机时间
    maxHour: 8,  // 倒计时随机最大小时
  },

  /**
   * 组件的方法列表
   */
  methods: {
    _getServeHeadData: function(config) {
      console.log('check config = ', config)
      // 初始化服务器配置
      if (!config.recent) return;
      const recent = config.recent;
      
      this.setData({
        headsArr: recent,
      });

      this._updateHeadAni();
      this._updateCountDown();
    },

    _initRpx: function() {
      // 适配屏幕移动距离
      wx.getSystemInfo({
        success: res => {
          let rpx = 1 * (res.windowWidth * res.pixelRatio) / (375 * res.pixelRatio);
          this.setData({
            rpx: rpx
          });
        },
      })
    },

    _randomCountDownTime: function(time) {
      if (time < 0) {
        this._stopInterval();
        return;
      }
      let hour = Math.floor(time / 3600) % 10;
      let minute = Math.floor((time / 60) % 60);
      let second = Math.floor(time % 60);
      let timeStr = '0' + hour + ':' + (minute < 10 ? ('0' &
  • 1
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

Valar Morgulish

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

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

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

打赏作者

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

抵扣说明:

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

余额充值