发布时间:2023-02-18 文章分类:编程知识 投稿人:王小丽 字号: 默认 | | 超大 打印

表格改成轮播表格效果

//使用表格组件
<el-table ref="waitTable" :data="waitApproData">
  <el-table-column label="标准集" prop="sortName"></el-table-column>
</el-table>

重点(js 设置部分)

//为表格添加事件
let isScroll = true;
nextTick(() => {
  let div: HTMLElement | null = document.querySelector(".el-table");
  console.log("div", div);
  if (div) {
    div.style.height = "330px";
    div.addEventListener("mouseenter", function() {
      isScroll = false;
    });
    div.addEventListener("mouseleave", function() {
      isScroll = true;
    });
    let t = document.querySelector(".el-table__body") as HTMLElement;
    if (t) {
      setInterval(() => {
        if (isScroll) {
          var data = waitApproData.value[0];
          setTimeout(() => {
            waitApproData.value.push(data);
            t.style.transition = "all .5s";
            t.style.marginTop = "-41px";
          }, 500);
          setTimeout(() => {
            waitApproData.value.splice(0, 1);
            t.style.transition = "all 0s ease 0s";
            t.style.marginTop = "0";
          }, 1000);
        }
      }, 2500);
    }
  }
});

设置 margin-top 变化是为了每条数据都产生一次位移效果,模拟向上滑动效果,如果只设置一次就只会第一条数据产生位移效果

涉及到的知识点

margin 设置为负值

  1. margin-left,margin-right:
  1. margin-top:
  1. margin-bottom:

css 属性 style.transition

参考