经验首页 前端设计 程序设计 Java相关 移动开发 数据库/运维 软件/图像 大数据/云计算 其他经验
当前位置:技术经验 » JS/JS库/框架 » Vue.js » 查看文章
vue使用动画实现滚动表格效果
来源:jb51  时间:2022/4/11 18:16:19  对本文有异议

本文实例为大家分享了vue使用动画实现滚动表格效果的具体代码,供大家参考,具体内容如下

需求

在一些大屏项目中,需要使用到表格行数据滚动。本文介绍在vue项目中使用动画实现滚动表格。

vue代码如下

  1. <template>
  2. ? <div style="cursor: default;margin:9px 10px 18px">
  3. ? ? <div class="table-header table-row">
  4. ? ? ? <div class="table-cell" style="width: 25%">计划名称</div>
  5. ? ? ? <div class="table-cell" style="width: 40%">核心企业</div>
  6. ? ? ? <div class="table-cell" style="width: 15%">发行状态</div>
  7. ? ? ? <div class="table-cell" style="width: 20%;text-align:right">金额(元)</div>
  8. ? ? </div>
  9. ? ? <div class="table-body">
  10. ? ? ? <div :class="{ 'scroll-wrap': getPlayData.length > 0 }">
  11. ? ? ? ? <div
  12. ? ? ? ? ? class="table-row"
  13. ? ? ? ? ? :class="{ hasBgc: index % 2 === 0 }"
  14. ? ? ? ? ? v-for="(item, index) in getPlayData"
  15. ? ? ? ? ? :key="index"
  16. ? ? ? ? ? :ref="'row_' + index"
  17. ? ? ? ? >
  18. ? ? ? ? ? <div class="table-cell" style="width: 25%" :title="item.productName">
  19. ? ? ? ? ? ? {{ item.productName }}
  20. ? ? ? ? ? </div>
  21. ? ? ? ? ? <div class="table-cell" style="width: 40%" :title="item.coreName">{{ item.coreName }}</div>
  22. ? ? ? ? ? <div class="table-cell" style="width: 15%" :title="item.publish">{{ item.publish }}</div>
  23. ? ? ? ? ? <div class="table-cell" style="width: 20%;text-align:right" :title="item.publishAmount">
  24. ? ? ? ? ? ? {{ item.publishAmount }}
  25. ? ? ? ? ? </div>
  26. ? ? ? ? </div>
  27. ? ? ? </div>
  28. ? ? </div>
  29. ? </div>
  30. </template>
  31. <script>
  32. export default {
  33. ? props: {
  34. ? ? data: {
  35. ? ? ? type: Array,
  36. ? ? ? default: () => {
  37. ? ? ? ? return [];
  38. ? ? ? },
  39. ? ? },
  40. ? },
  41. ? data() {
  42. ? ? return {
  43. ? ? ? initMt: 0,
  44. ? ? ? // getPlayData:[],
  45. ? ? ? visible: true,
  46. ? ? ? stop: false,
  47. ? ? };
  48. ? },
  49. ? methods: {
  50. ? ? play() {
  51. ? ? ? const row = this.$refs["row_0"][0];
  52.  
  53. ? ? ? setTimeout(() => {
  54. ? ? ? ? this.visible = false;
  55.  
  56. ? ? ? ? this.$nextTick(() => {
  57. ? ? ? ? ? this.initMt++;
  58. ? ? ? ? ? if (this.initMt === this.data.length) {
  59. ? ? ? ? ? ? this.initMt = 0;
  60. ? ? ? ? ? }
  61. ? ? ? ? ? this.visible = true;
  62. ? ? ? ? });
  63. ? ? ? ? this.play();
  64. ? ? ? }, 2000);
  65. ? ? },
  66. ? },
  67. ? watch: {
  68.  
  69. ? },
  70. ? computed: {
  71. ? ? getPlayData() {
  72. ? ? ? return this.data.concat(this.data.slice(0, 4));
  73. ? ? },
  74. ? },
  75. ? mounted() {
  76. ? ? // this.play();
  77. ? },
  78. };
  79. </script>
  80. <style lang="scss" scoped>
  81. $cellHeight: 35px;
  82. .table-row {
  83. ? display: flex;
  84. ? line-height: 35px;
  85. ? height: 35px;
  86. ? transition: all 0.3s;
  87. ? border-bottom: 1px solid rgba(63, 88, 114, 1);
  88. }
  89. .table-header {
  90. ? color: rgba(87, 150, 190, 1);
  91. }
  92. .table-cell {
  93. ? text-align: left;
  94. ? font-size: 12px;
  95. ? text-overflow: ellipsis;
  96. ? overflow: hidden;
  97. }
  98. // .hasBgc {
  99. // ? background: rgb(0, 59, 81);
  100. // }
  101. .hidden-row {
  102. ? height: 0 !important;
  103. ? line-height: 0 !important;
  104. ? display: none !important;
  105. }
  106. .table-body {
  107. ? height: 142px;
  108. ? overflow-y: hidden;
  109. ? .table-row {
  110. ? ? color: #fff;
  111. ? }
  112. }
  113. .scroll-wrap {
  114. ? animation: scroll 18s linear infinite;
  115. ? position: relative;
  116. }
  117. .scroll-wrap:hover {
  118. ? animation-play-state: paused;
  119. }
  120. @keyframes scroll {
  121. ? from {
  122. ? ? top: 0;
  123. ? }
  124. ? to {
  125. ? ? top: -8 * $cellHeight;
  126. ? }
  127. }
  128. </style>

通过动画动态改变表格的位置来达到移动的效果。把数据的一半拼接在原数据上作为滚动数据,达到衔接的效果。

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持w3xue。

 友情链接:直通硅谷  点职佳  北美留学生论坛

本站QQ群:前端 618073944 | Java 606181507 | Python 626812652 | C/C++ 612253063 | 微信 634508462 | 苹果 692586424 | C#/.net 182808419 | PHP 305140648 | 运维 608723728

W3xue 的所有内容仅供测试,对任何法律问题及风险不承担任何责任。通过使用本站内容随之而来的风险与本站无关。
关于我们  |  意见建议  |  捐助我们  |  报错有奖  |  广告合作、友情链接(目前9元/月)请联系QQ:27243702 沸活量
皖ICP备17017327号-2 皖公网安备34020702000426号