MoveGroup.vue 3.27 KB
<template>
  <div class="group-list" ref="groupBox">
    <div class="mask"></div>
    <template v-if="list.length">
      <div class="move" ref="move">
        <template v-for="(i, index) in list">
          <div :class="['item flex', { 'group-item': index == 0 }]" :key="index">
            <img :src="i.imageUrl" />
            <div class="text">{{ i.name }}刚刚参加了活动</div>
          </div>
        </template>
      </div>
    </template>
  </div>
</template>

<script type="text/ecmascript-6">
export default {
  name: 'MoveGroup',
  props: {
    groupInfo: {
      type: Object,
      default: () => { }
    },
    show: {
      type: Boolean,
      default: false
    }
  },
  watch: {
    'show' (n) {
      let { groupInfo } = this
      if (n && groupInfo.groupList && groupInfo.groupList.length) this.setList(groupInfo.groupList)
    }
  },
  data () {
    return {
      list: [],
      speed: 0.8
    }
  },
  mounted () {
    this.$refs.groupBox.style.display = 'none'
  },
  methods: {

    setList (list) {
      this.list = list
      this.$refs.groupBox.style.display = 'block'
      let timer = setTimeout(() => {
        this.animation(list)
        clearTimeout(timer)
      }, 100)
    },
    animation (list) {
      let boxHeight = this.$refs.groupBox.offsetHeight
      let [item] = document.getElementsByClassName('group-item')
      let itemHeight = item.offsetHeight / 7 + item.offsetHeight
      let groupHeight = `${itemHeight * list.length}`
      let { speed } = this
      let rule = `@keyframes rowup {
                    0% {transform: translateY(${boxHeight}px);}
                    100% {transform: translateY(-${groupHeight}px);}
                    }`
      let sheet = document.styleSheets[0]
      sheet.insertRule(rule, 0)
      let duration = this.decimal(speed * list.length + (boxHeight / itemHeight * speed), 2)
      this.$refs.move.style.animation = `${duration}s rowup linear infinite normal`
    }
  }
}
</script>

<style scoped lang="scss">
.group-list {
  // visibility: hidden;
  position: absolute;
  left: 8px;
  top: 5%;
  width: 180px;
  height: 80%;
  overflow: hidden;
  .move {
    width: 100%;
  }
  .item {
    position: relative;
    display: inline-flex;
    padding: 0 6px 0 3px;
    box-sizing: border-box;
    height: 28px;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 17px;
    margin-bottom: 4px;
    font-size: 12px;
    font-weight: 500;
    color: #ffffff;
    img {
      width: 22px;
      height: 22px;
      border-radius: 100%;
      overflow: hidden;
      margin-right: 3px;
    }
  }
  @keyframes opacity-text {
    0% {
      opacity: 1;
    }
    100% {
      opacity: 0;
    }
  }
  .first {
    background: linear-gradient(180deg, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 0.5) 100%);
    .text {
      background: linear-gradient(180deg, rgba(255, 255, 255, 0) 0%, #ffffff 100%);
      -webkit-background-clip: text;
      -webkit-text-fill-color: transparent;
    }
    // animation: opacity-text 5s forwards;
  }
  .last {
    background: linear-gradient(360deg, rgba(0, 0, 0, 0) 0%, rgba(0, 0, 0, 0.5) 100%);
    .text {
      background: linear-gradient(360deg, rgba(255, 255, 255, 0) 0%, #ffffff 100%);
      -webkit-background-clip: text;
      -webkit-text-fill-color: transparent;
    }
  }
}
.show {
  visibility: visible;
}
</style>