vue 实现table的无限滚动

<template>

  <div class="wrapper" @mouseover="mouseOver" @mouseout="mouseOut">

    <table class="totall">

      <tr class="title">
        <th v-for="itemx in liData" :key="itemx">{{ itemx }}</th>


      </tr>
    </table>

        
    <div ref="moocBox" class="wrapper2">
          
      <table :class="{ marquee_top: animate }">
              
        <tr v-for="itemy in listData" class="rollData" ref="con1" :key="itemy">
                  
          <td v-for="itemz in itemy" :key="itemz">{{ itemz }}</td>

                
        </tr>

              
        <tr v-for="itemy in listData" class="rollData" ref="con2" :key="itemy">
                  
          <td v-for="itemz in itemy" :key="itemz">{{ itemz }}</td>

                
        </tr>

            
      </table>

          
    </div>

      
  </div>
</template>

<script>
export default {
  name: "Profile",

  data() {
    return {
      animate: false,

      liData: ["重点品类", "销售金额", "年周比", "达成率"],

      listData: [
        ["FM", "53.647", "-33.76", "86.15%"],

        ["A", "53.647", "-33.76", "86.15%"],

        ["B", "53.647", "-33.76", "86.15%"],

        ["C", "53.647", "-33.76", "86.15%"],

        ["D", "53.647", "-33.76", "86.15%"],

        ["E", "53.647", "-33.76", "86.15%"],

        ["F", "53.647", "-33.76", "86.15%"],

        ["G111", "53.647", "-33.76", "86.15%"],
      ],

      speed: 50,

      myScroll: null,

      iliHeight: 26,

      time: null,

      delay: 20,
    };
  },

  methods: {
    //滚动

    scrollUp() {
      this.$refs.moocBox.scrollTop++;
        // console.log(this.$refs.moocBox);
      if (this.$refs.moocBox.scrollTop >= this.$refs.moocBox.scrollHeight / 2) {
        //判断条件是否达到临界

        this.$refs.moocBox.scrollTop = 0;
      } else {
        this.$refs.moocBox.scrollTop++;
      }
    }, // 鼠标滑过暂停滚动

    mouseOver() {
      clearInterval(this.myScroll);
    }, //鼠标移开重新滚动

    mouseOut() {
      this.myScroll = setInterval(
        () => {
          this.$refs.moocBox.scrollTop++;

          this.scrollUp();
        },

        this.speed
      );
    },
  },

  components: {},

  computed: {},

  created() {},

  mounted() {
    this.myScroll = setInterval(() => {
      this.$refs.moocBox.scrollTop++;

      this.scrollUp();
    }, this.speed);
  },

  activated() {},

  deactivated() {},

  beforeDestoryed() {
    clearInterval(myScroll);

    this.myScroll = null;
  },
};
</script>

<style scoped>
.wrapper {
  overflow: hidden;

  height: 220px;
}

.wrapper2 {
  height: 180px;

  overflow: hidden;
}

table {
  border-collapse: collapse;

  border-spacing: 0;

  table-layout: fixed;

  background-color: rgb(2,  25,  80);

  width: 100%;

  color: rgb(141, 35, 35);
}

tabletr {
transition: all 2s ease .3s;
}

.marquee_top  {
      transition: all 0.5s ease-in-out;

      margin-top: -26px;
}

.title  {
    height: 40px;

    line-height: 40px;

    text-align: center;
}

th {
     padding: 5px 10px;

     width: 25%;
}

td {
     padding: 4px 10px;

     width: 25%;
}

table th {
    text-align: center;
}

table tr td  {
    width: 25%;

    text-align: center;
}

.rollData  {
    font-size: 16px;
}
</style>

  • 2
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

Z_Xshan

你的鼓励是我最大的动力

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

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

打赏作者

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

抵扣说明:

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

余额充值