当前位置:   article > 正文

vue 实现table的无限滚动_vue table 滚动

vue table 滚动
  1. <template>
  2. <div class="wrapper" @mouseover="mouseOver" @mouseout="mouseOut">
  3. <table class="totall">
  4. <tr class="title">
  5. <th v-for="itemx in liData" :key="itemx">{{ itemx }}</th>
  6. </tr>
  7. </table>
  8.     
  9. <div ref="moocBox" class="wrapper2">
  10.     
  11. <table :class="{ marquee_top: animate }">
  12.       
  13. <tr v-for="itemy in listData" class="rollData" ref="con1" :key="itemy">
  14.         
  15. <td v-for="itemz in itemy" :key="itemz">{{ itemz }}</td>
  16.       
  17. </tr>
  18.       
  19. <tr v-for="itemy in listData" class="rollData" ref="con2" :key="itemy">
  20.         
  21. <td v-for="itemz in itemy" :key="itemz">{{ itemz }}</td>
  22.       
  23. </tr>
  24.     
  25. </table>
  26.     
  27. </div>
  28.   
  29. </div>
  30. </template>
  31. <script>
  32. export default {
  33. name: "Profile",
  34. data() {
  35. return {
  36. animate: false,
  37. liData: ["重点品类", "销售金额", "年周比", "达成率"],
  38. listData: [
  39. ["FM", "53.647", "-33.76", "86.15%"],
  40. ["A", "53.647", "-33.76", "86.15%"],
  41. ["B", "53.647", "-33.76", "86.15%"],
  42. ["C", "53.647", "-33.76", "86.15%"],
  43. ["D", "53.647", "-33.76", "86.15%"],
  44. ["E", "53.647", "-33.76", "86.15%"],
  45. ["F", "53.647", "-33.76", "86.15%"],
  46. ["G111", "53.647", "-33.76", "86.15%"],
  47. ],
  48. speed: 50,
  49. myScroll: null,
  50. iliHeight: 26,
  51. time: null,
  52. delay: 20,
  53. };
  54. },
  55. methods: {
  56. //滚动
  57. scrollUp() {
  58. this.$refs.moocBox.scrollTop++;
  59. // console.log(this.$refs.moocBox);
  60. if (this.$refs.moocBox.scrollTop >= this.$refs.moocBox.scrollHeight / 2) {
  61. //判断条件是否达到临界
  62. this.$refs.moocBox.scrollTop = 0;
  63. } else {
  64. this.$refs.moocBox.scrollTop++;
  65. }
  66. }, // 鼠标滑过暂停滚动
  67. mouseOver() {
  68. clearInterval(this.myScroll);
  69. }, //鼠标移开重新滚动
  70. mouseOut() {
  71. this.myScroll = setInterval(
  72. () => {
  73. this.$refs.moocBox.scrollTop++;
  74. this.scrollUp();
  75. },
  76. this.speed
  77. );
  78. },
  79. },
  80. components: {},
  81. computed: {},
  82. created() {},
  83. mounted() {
  84. this.myScroll = setInterval(() => {
  85. this.$refs.moocBox.scrollTop++;
  86. this.scrollUp();
  87. }, this.speed);
  88. },
  89. activated() {},
  90. deactivated() {},
  91. beforeDestoryed() {
  92. clearInterval(myScroll);
  93. this.myScroll = null;
  94. },
  95. };
  96. </script>
  97. <style scoped>
  98. .wrapper {
  99. overflow: hidden;
  100. height: 220px;
  101. }
  102. .wrapper2 {
  103. height: 180px;
  104. overflow: hidden;
  105. }
  106. table {
  107. border-collapse: collapse;
  108. border-spacing: 0;
  109. table-layout: fixed;
  110. background-color: rgb(2,  25,  80);
  111. width: 100%;
  112. color: rgb(141, 35, 35);
  113. }
  114. tabletr {
  115. transition: all 2s ease .3s;
  116. }
  117. .marquee_top  {
  118.     transition: all 0.5s ease-in-out;
  119.     margin-top: -26px;
  120. }
  121. .title  {
  122.   height: 40px;
  123.   line-height: 40px;
  124.   text-align: center;
  125. }
  126. th {
  127.    padding: 5px 10px;
  128.    width: 25%;
  129. }
  130. td {
  131.    padding: 4px 10px;
  132.    width: 25%;
  133. }
  134. table th {
  135.   text-align: center;
  136. }
  137. table tr td  {
  138.   width: 25%;
  139.   text-align: center;
  140. }
  141. .rollData  {
  142.   font-size: 16px;
  143. }
  144. </style>

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/193854
推荐阅读