使用Vue+ElementUI+VUE-Seamless-Scroll实现火车时刻表滚动功能

目录

1.环境:

2.代码:

3.最后结果:

4.注意:


1.环境:

1)Vue

2)Element UI

3)安装 vue-seamless-scroll

      npm:

npm install vue-seamless-scroll --save

    静态页面:

<script src="vue-seamless-scroll.min.js"></script>

2.代码:

<template>
    <div class="content">

            <section style="height: 1340px">

              <el-table style="width: 100%; height:100px;"
                        :header-cell-class-name="getHeadRowClass" >
                <el-table-column prop="order" label="序号" width="100px" height="100px"></el-table-column>
                <el-table-column prop="name" label="企业名称" width="400px"  height="100px" ></el-table-column>
                <el-table-column prop="month" label="列1" width="235px"  height="100px"></el-table-column>
                <el-table-column prop="daily" label="列2"  width="235px"  height="100px"></el-table-column>
                <el-table-column prop="hour" label="列3"  width="235px"  height="100px"></el-table-column>
                <el-table-column prop="guishang" label="列4"  width="100px"  height="100px"></el-table-column>
                <el-table-column prop="status" label="列5"  width="100px"  height="100px"></el-table-column>
                <el-table-column prop="substatus" label="列6"  width="260px"  height="100px"></el-table-column>
              </el-table>

              <vue-seamless-scroll :data="companyList"  class="auto-scorll-table" :class-option="classOption">
                <el-table
                          :data="companyList"
                          class="custom-table-2 hidden-thead"
                          :show-header="false"
                          :stripe="true"
                          :header-cell-class-name="getItemRowClass">
                  <el-table-column prop="order" label="序号" width="100px" height="100px"></el-table-column>
                  <el-table-column prop="name" label="企业名称" width="400px"  height="100px" ></el-table-column>
                  <el-table-column prop="month" label="列1" width="235px"  height="100px"></el-table-column>
                  <el-table-column prop="daily" label="列2"  width="235px"  height="100px"></el-table-column>
                  <el-table-column prop="hour" label="列3"  width="235px"  height="100px"></el-table-column>
                  <el-table-column prop="guishang" label="列4"  width="100px"  height="100px"></el-table-column>
                  <el-table-column prop="status" label="列5"  width="100px"  height="100px"></el-table-column>
                  <el-table-column prop="substatus" label="列6"  width="260px"  height="100px"></el-table-column>
                </el-table>
              </vue-seamless-scroll>

            </section>
    </div>
</template>

<script>

export default {
  name: "LeftBox1",
  components: {

  },
  data() {
    return {
      companyList: [{
        'order':1,
        'name': '无缝滚动第一行无缝滚动第一行',
        'month': 123123213,
        'daily': 123123123,
        'hour': 12312312,
        'guishang':'是',
        'status':'生产'

      }, {
        'order':2,
        'name': '无缝滚动第一行无缝滚动第一行无缝滚动第一行无缝滚动第一行无缝滚动第一行无缝滚动第一行无缝滚动第一行无缝滚动第一行',
        'month': 123123213,
        'daily': 123123123,
        'hour': 12312312,
        'guishang':'是',
        'status':'生产'

      }, {
        'order':3,
        'name': '无缝滚动第一行无缝滚动第一行',
        'month': 123123213,
        'daily': 123123123,
        'hour': 12312312,
        'guishang':'是',
        'status':'生产'
      }, {
        'order':4,
        'name': '无缝滚动第一行无缝滚动第一行',
        'month': 123123213,
        'daily': 123123123,
        'hour': 12312312,
        'guishang':'是',
        'status':'生产'
      }, {
        'order':5,
        'name': '无缝滚动第一行无缝滚动第一行',
        'month': 123123213,
        'daily': 123123123,
        'hour': 12312312,
        'guishang':'是',
        'status':'生产'
      }, {
        'order':6,
        'name': '无缝滚动第一行无缝滚动第一行',
        'month': 123123213,
        'daily': 123123123,
        'hour': 12312312,
        'guishang':'是',
        'status':'生产'
      }, {
        'order':7,
        'name': '无缝滚动第一行无缝滚动第一行',
        'month': 123123213,
        'daily': 123123123,
        'hour': 12312312,
        'guishang':'是',
        'status':'生产'
      }, {
        'order':8,
        'name': '无缝滚动第一行无缝滚动第一行',
        'month': 123123213,
        'daily': 123123123,
        'hour': 12312312,
        'guishang':'是',
        'status':'生产'
      }, {
        'order':9,
        'name': '无缝滚动第一行无缝滚动第一行',
        'month': 123123213,
        'daily': 123123123,
        'hour': 12312312,
        'guishang':'是',
        'status':'生产'
      },
      ...],
    }
  },
  async mounted() {
        this.init();
  },
  methods: {
    init(){
      this.getCompanyList();
    },
    getCompanyList(){
      let that = this;
      this.$axios({
        method: "get",
        url: `/api/Company/companyInfoList`,
        params: {'date': this.$parent.endData },
        headers: {
          'Content-type': 'application/x-www-form-urlencoded'
        },
      }).then((res) => {
        if (res.data.code != 200) {
          return null;
        }
        that.companyList = []

        for (let i = 0; i < res.data.data.length; i++) {
          let item = res.data.data[i]
          item.month = (item.month/10000).toFixed(2);
          that.companyList.push(item);
        }
      });
    },
    getHeadRowClass() {
      return 'headerTitle';
    },
    getItemRowClass(){
      return 'itemStyle';
    } 
  },
  computed: {
    classOption () {
      return {
        step: 1, // 数值越大速度滚动越快
        limitMoveNum: this.companyList.length, // 开始无缝滚动的数据量 this.dataList.length
        hoverStop: true, // 是否开启鼠标悬停stop
        direction: 1, // 0向下 1向上 2向左 3向右
        openWatch: true, // 开启数据实时监控刷新dom
        singleHeight: 0, // 单步运动停止的高度(默认值0是无缝不停止的滚动) direction => 0/1
        singleWidth: 0, // 单步运动停止的宽度(默认值0是无缝不停止的滚动) direction => 2/3
        waitTime: 1000 // 单步运动停止的时间(默认值1000ms)
      }
    },
  }
};
</script>

<style lang="scss" scoped>

.content {
  width: 100%;
  height: 1650px;
  padding-top: 112px;
  padding-left: 159px;
  padding-right: 94px;
  title{

  }
}
.content /deep/ .el-table--fit{
  text-align: center;
}

.content /deep/  .el-table, .el-table__expanded-cell {
  background-color: transparent;
}

.content /deep/ .el-table tr {
  background-color: transparent!important;
  height: 100px;
}
.content /deep/  .el-table--enable-row-transition .el-table__body td, .el-table .cell{
  background-color: transparent;
}

.content /deep/ .el-table .headerTitle {
  background: #073265;
  font-size: 28px;
  font-family: Microsoft YaHei;
  font-weight: 400;
  color: #ffffff;
  text-align: center;
  height:100px
}

.content /deep/ .el-table .headerTitle .cell {
 line-height: 30px;
}

.content /deep/ .el-table--enable-row-transition .el-table__body td,
                .el-table .cell .itemStyle{

  font-size: 28px;
  font-family: Microsoft YaHei;
  font-weight: 400;
  color: #ffffff;
  text-align: center;

}

.content /deep/ .el-table .cell{
  line-height: 35px;
}
</style>

3. 最后结果:

最后执行结果,就像是我们在火车站看见的列车时刻表一样,从下到上滚动显示每条信息:

使用VUE+ElementUI实现火车时刻表滚动功能

4.注意:

     如果我们的数据集合数量不够,会导致显示的时候不能出现连续滚动的情况,这时候,我们只要将我们的数据集合进行适当的扩充。例如,companyList里面包含3条数据{A,B,C}, 我们只需要将companyList里面的内容,重复的填充成为{A,B,C,A,B,C,A,B,C,A,B,C}  

    官网地址 vue-seamless-scroll

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

IT小悟

你的鼓励将是我创作的最大动力

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

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

打赏作者

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

抵扣说明:

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

余额充值