走马灯效果 滚动条

<template>
  <div class="all" ref="scrollingContainer">
    <div
      class="transition_tipa"
      v-for="(item, index) in tableList"
      :key="index"
    >
      <img
        :src="item.coinImg"
        alt=""
        style="width:32px;height:32px;border-radius:50%;margin-right:10px;"
      />
      <div class="transition_tipa_title">{{ item.symbol }}</div>
      <div class="transition_tipa_title">${{ item.open }}</div>
      <div class="transition_tipa_title">({{(((item.high - item.close) / item.open) * 100).toFixed(2)}}%)</div>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      tableList: [],
      scrollTimer: null, // 用来存储定时器的变量
      scrollPosition: 0, // 用来存储当前的滚动位置
      screenWidth: window.innerWidth,
    };
  },
  created() {
    this.getOverviewval();
  },
  mounted() {
    this.startScrolling();
    window.addEventListener("resize", this.updateScreenSize);
  },
  beforeDestroy() {
    this.stopScrolling();
    window.removeEventListener("resize", this.updateScreenSize);
  },
  methods: {
    startScrolling() {
      this.scrollTimer = setInterval(() => {
        this.scrollPosition += 1;
        this.$refs.scrollingContainer.scrollLeft = this.scrollPosition;
        if (
          this.scrollPosition >=
          this.tableList.length * 500 - this.screenWidth
        ) {
          this.scrollPosition = 0;
          this.scrollTimer;
        }
      }, 50);
    },
    stopScrolling() {
      clearInterval(this.scrollTimer);
      this.scrollTimer = null;
    },
    updateScreenSize() {
      this.screenWidth = window.innerWidth;
    },
    getOverviewval() {
      this.$http.post(this.host + this.api.index.getOverview).then((res) => {
        this.tableList = res.data.data;
      });
    },
  },
};
</script>

<style scoped lang="less">
.all {
  display: flex;
  align-items: center;
  overflow-x: auto;
  width: 100%;
  overflow: hidden;
}

.transition_tipa {
  min-width: 500px;
  height: 50px;
  display: flex;
  align-items: center;
  font-size: 20px;
  color: #fff;
}
.transition_tipa_title{
    margin-right: 20px;
}
</style>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值