加入收藏 | 设为首页 | 会员中心 | 我要投稿 PHP编程网 - 黄冈站长网 (http://www.0713zz.com/)- 数据应用、建站、人体识别、智能机器人、语音技术!
当前位置: 首页 > 综合聚焦 > 编程要点 > 语言 > 正文

用CSS做滚动表格的效果的方法

发布时间:2023-12-27 12:45:58 所属栏目:语言 来源:DaWei
导读: 这篇文章给大家分享的是用CSS怎么样做滚动表格的效果的示例。小编觉得挺实用的,因此分享给大家做个参考,文中的示例代码介绍得很详细,有需要的朋友可以参考,接下来就跟随小编一起了解看看
这篇文章给大家分享的是用CSS怎么样做滚动表格的效果的示例。小编觉得挺实用的,因此分享给大家做个参考,文中的示例代码介绍得很详细,有需要的朋友可以参考,接下来就跟随小编一起了解看看吧。

<template>
  <section>
    <div class="box">
      <ul class="header">
        <li class="cell">序号</li>
        <li class="cell">姓名</li>
        <li class="cell">年龄</li>
        <li class="cell">性别</li>
        <li class="cell">专业</li>
      </ul>
      <div class="body">
        <ul class="list">
          <li
            v-for="(item, index) in arr"
            :key="index"
            class="row"
          >
            <span class="cell">{{ item }}</span>
            <span v-for="(n) in 4" :key="n*30" class="cell">{{ n }}</span>
          </li>
        </ul>
      </div>
    </div>
  </section>
</template>

<script>
export default {
  data() {
    return {
      arr: [],
    }
  },
  created() {
    this.arr = Array.from(new Array(20), (v, k) => {
      return k + 1
    })
    // 表格显示5行数据,此处复制开头的5条数据实现无缝
    this.arr = this.arr.concat(this.arr.slice(0, 5))
  }
}
</script>

<style lang="scss">
$cellHeight: 30px;
ul {
  list-style: none;
  margin: 0;
  padding: 0;
}
.box {
  width: 60%;
  margin: auto;
}
.header {
  display: flex;
}
.body {
  height: 5 * $cellHeight;
  overflow: hidden;
  // padding-bottom: 10px;
  li {
    display: flex;
    height: $cellHeight;
  }
}
.cell {
  flex: 1;
  height: $cellHeight;
  line-height: $cellHeight;
  border: 1px solid #e2e2e2;
  box-sizing: border-box;
}
.list {
  animation: scroll 10s  linear infinite;
  position: relative;
}

@keyframes scroll {
  from { top: 0; }
  to { top: -20 * $cellHeight }
}
</style>

以上就是用CSS实现滚动表格的效果的介绍,上述示例具有一定的参考价值,有需要的朋友可以了解看看,希望对大家学习CSS的使用有帮助。

(编辑:PHP编程网 - 黄冈站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章