posterIndex.vue 8.05 KB
<template>
  <!-- offset="-100px" offset="1"-->
  <Scrollama @step-enter="stepEnterHandler" :offset="0.7">
    <!-- <img class="img" src="./image/1.jpg" alt="" /> -->
    <div
      v-for="(el, index) in imgList"
      :key="index"
      class="image-container"
      :data-step="`${index}`"
      :style="{ height: getImageHeight(index) }"
    >
      <img :src="`${baseimgUrl}${index + 1}.jpg`" alt="" />
      <!-- <div v-if="index ==4" :ref="`count${index}`"></div> -->
      <img
        class="mapstar"
        v-if="index == 3"
        :src="`${baseimgUrl}mapstar.gif`"
        alt=""
      />
      <!--         :suffix="item.suffix || ''" -->
      <span v-for="item in el.countList || []" :key="item.refName">
        <!--  -->
        <countTo
          :style="item.style"
          class="count-to-style"
          :ref="item.refName"
          :startVal="item.startVal"
          :endVal="item.endVal"
          :autoplay="false"
          :duration="item.duration"
          separator=""
          :decimals="item.decimals || 0"
          :class="item.className || ''"
        ></countTo>
        <span class="suffix" :style="item.suffixStyle">{{
          item.suffix || ""
        }}</span>
      </span>
    </div>
  </Scrollama>
</template>

<script>
import "intersection-observer"; // for cross-browser support
import Scrollama from "vue-scrollama"; // local registration in this example, can also be globally registered
import countTo from "vue-count-to";
export default {
  components: {
    Scrollama, // local registration in this example, can also be globally registered
    countTo,
  },
  data() {
    return {
      baseimgUrl:
        "https://img02.glsx.com.cn/weapp/resource/qiwei/13years-poster/",
      imgList: [
        {
          height: 266.67,
        },
        {
          height: 111.2,
          countList: [
            {
              refName: "count01",
              startVal: 0,
              endVal: 7,
              duration: 3000,
              style: {
                top: "49.1%",
                left: "9%",
              },
            },
            {
              refName: "count02",
              startVal: 0,
              endVal: 4.3,
              decimals: 1,
              duration: 4000,
              className: "count02",
              style: {
                top: "49.1%",
                left: "39.5%",
              },
            },
          ],
        },
        {
          height: 262.93,
        },
        {
          height: 135.2,
          countList: [
            {
              refName: "count31",
              startVal: 0,
              endVal: 74,
              duration: 2000,
              suffix: "%+",
              style: {
                top: "80.5%",
                left: "27%",
              },
              suffixStyle: {
                top: "80.5%",
                left: "37.5%",
              },
            },
            {
              refName: "count32",
              startVal: 0,
              endVal: 4000,
              duration: 1500,
              suffix: "+",
              style: {
                top: "86.79%",
                left: "36%",
              },
              suffixStyle: {
                top: "86.79%",
                left: "54.8%",
              },
            },
          ],
        },
        {
          height: 170.4,
          countList: [
            {
              refName: "count41",
              startVal: 0,
              endVal: 50,
              duration: 2000,
              suffix: "%+",
              style: {
                top: "33.5%",
                left: "14%",
              },
              suffixStyle: {
                top: "33.5%",
                left: "24.53%",
              },
            },
            {
              refName: "count42",
              startVal: 0,
              endVal: 30,
              duration: 2000,
              suffix: "%+",
              style: {
                top: "49%",
                left: "14%",
              },
              suffixStyle: {
                top: "49%",
                left: "24.53%",
              },
            },
          ],
        },
        {
          height: 190.75,
          countList: [
            {
              refName: "count61",
              startVal: 0,
              endVal: 25,
              duration: 3000,
              style: {
                fontSize: "7vw",
                top: "75.7%",
                left: "29%",
              },
            },
            {
              refName: "count62",
              startVal: 0,
              endVal: 4,
              duration: 5000,
              style: {
                fontSize: "7vw",
                top: "75.5%",
                left: "75.5%",
              },
            },
            {
              refName: "count63",
              startVal: 0,
              endVal: 58,
              duration: 3000,
              style: {
                fontSize: "7vw",
                top: "83.5%",
                left: "29.9%",
              },
            },
            {
              refName: "count64",
              startVal: 0,
              endVal: 94,
              duration: 3000,
              style: {
                fontSize: "7vw",
                top: "83.5%",
                left: "68%",
              },
            },
            {
              refName: "count65",
              startVal: 0,
              endVal: 21,
              duration: 3000,
              style: {
                fontSize: "7vw",
                top: "91.2%",
                left: "29.5%",
              },
            },
            {
              refName: "count66",
              startVal: 0,
              endVal: 82,
              duration: 3000,
              style: {
                fontSize: "7vw",
                top: "91.2%",
                left: "74.5%",
              },
            },
          ],
        },
        {
          height: 108.7,
        },
        {
          height: 255.55,
        },
        {
          height: 188.88,
        },
        {
          height: 222.21,
        },
        {
          height: 211.12,
        },
        {
          height: 251.84,
        },
        {
          height: 282.66,
        },
      ],
      duration: 600000,
    };
  },
  computed: {
    getImageHeight() {
      return (index) => {
        // console.log(this.imgList, this.imgList[index]);
        return this.imgList[index].height + "vw";
      };
    },
  },
  methods: {
    start() {
      console.log(this.$refs.count1, "this.$refs.count1");
      this.$refs.count1[0].start();
    },
    stepEnterHandler({ element, index, direction }) {
      // handle the step-event as required here
      console.log({ element, index, direction });
      // use the data attributes if needed
      console.log(element.dataset.step); // a, b or c
      if (this.imgList[index]?.countList) {
        this.imgList[index].countList.forEach((item) => {
          console.log(item);
          console.log(this.$refs[item.refName][0]);
          this.$refs[item.refName][0].start();
        });
      }

      // if (element.dataset.step == 13) {
      //   console.log("step a");
      //   this.start();
      // }
    },
  },
};
</script>

<style lang="scss" scoped>
.image-container {
  position: relative;
  min-height: 400px; /* 固定高度 */
  font-size: 30px;
  color: #024ad7;
  /* overflow: hidden;  */
  /* 可选,隐藏溢出部分 */
  img {
    width: 100%;
    height: 100%;
    object-fit: cover; /* 保持比例填充容器 */
  }
  .mapstar {
    width: 93%;
    height: 55%;
    position: absolute;
    top: 23.5%;
    left: 3.2%;
  }
}

.count-to-style {
  z-index: 999;
  position: absolute;
  // left: 0;
  // top: 0;
  font-family: number;
}
.suffix {
  z-index: 999;
  position: absolute;
  font-family: number;
}
// .count02 {
//   top: 207px;
//   left: 147px;
// }
</style>