MoveGroup.js 1.28 KB
// pages/crowdfunding/components/MoveGroup/MoveGroup.js
import util from '~/utils/util'
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    show: {
      type: Boolean,
      value: false,
      observer: function (n) {
        let { groupList } = this.data.groupInfo
        if (n && groupList && groupList.length) {
          this.setData({
            list: groupList
          })
          this.animation(groupList)
        }
      }
    },
    groupInfo: {
      type: Object,
      value: () => { }
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    list: [],
    speed: 0.8,
    displayNums: 1
  },

  /**
   * 组件的方法列表
   */
  methods: {
    animation(list) {
      let _this = this
      var query = this.createSelectorQuery()
      query.select('#groupBox').boundingClientRect()
      query.select('.group-item').boundingClientRect()
      query.exec(function (res) {
        const boxHeight = res[0].height
        const itemHeight = res[1].height
        if (boxHeight < itemHeight) {
          let timer = setTimeout(() => {
            _this.animation(list)
            clearTimeout(timer)
          }, 300)
        } else {
          _this.setData({
            displayNums: res[0].height / res[1].height
          })
        }
      })
    }
  }
})