seamless-scroll.vue 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  1. <script setup lang="ts">
  2. import { ref, reactive, unref } from "vue";
  3. import SeamlessScroll from "@/components/ReSeamlessScroll";
  4. defineOptions({
  5. name: "SeamlessScroll"
  6. });
  7. const scroll = ref();
  8. const listData = ref([
  9. {
  10. title: "无缝滚动第一行无缝滚动第一行!!!!!!!!!!"
  11. },
  12. {
  13. title: "无缝滚动第二行无缝滚动第二行!!!!!!!!!!"
  14. },
  15. {
  16. title: "无缝滚动第三行无缝滚动第三行!!!!!!!!!!"
  17. },
  18. {
  19. title: "无缝滚动第四行无缝滚动第四行!!!!!!!!!!"
  20. },
  21. {
  22. title: "无缝滚动第五行无缝滚动第五行!!!!!!!!!!"
  23. },
  24. {
  25. title: "无缝滚动第六行无缝滚动第六行!!!!!!!!!!"
  26. },
  27. {
  28. title: "无缝滚动第七行无缝滚动第七行!!!!!!!!!!"
  29. },
  30. {
  31. title: "无缝滚动第八行无缝滚动第八行!!!!!!!!!!"
  32. },
  33. {
  34. title: "无缝滚动第九行无缝滚动第九行!!!!!!!!!!"
  35. }
  36. ]);
  37. const classOption = reactive({
  38. direction: "top"
  39. });
  40. function changeDirection(val) {
  41. (unref(scroll) as any).reset();
  42. unref(classOption).direction = val;
  43. }
  44. </script>
  45. <template>
  46. <el-space wrap>
  47. <el-card class="box-card" shadow="never">
  48. <template #header>
  49. <div class="card-header">
  50. <span class="font-medium">无缝滚动</span>
  51. <el-button
  52. class="button"
  53. link
  54. type="primary"
  55. @click="changeDirection('top')"
  56. >
  57. <span
  58. :style="{ color: classOption.direction === 'top' ? 'red' : '' }"
  59. >
  60. 向上滚动
  61. </span>
  62. </el-button>
  63. <el-button
  64. class="button"
  65. link
  66. type="primary"
  67. @click="changeDirection('bottom')"
  68. >
  69. <span
  70. :style="{
  71. color: classOption.direction === 'bottom' ? 'red' : ''
  72. }"
  73. >
  74. 向下滚动
  75. </span>
  76. </el-button>
  77. <el-button
  78. class="button"
  79. link
  80. type="primary"
  81. @click="changeDirection('left')"
  82. >
  83. <span
  84. :style="{ color: classOption.direction === 'left' ? 'red' : '' }"
  85. >
  86. 向左滚动
  87. </span>
  88. </el-button>
  89. <el-button
  90. class="button"
  91. link
  92. type="primary"
  93. @click="changeDirection('right')"
  94. >
  95. <span
  96. :style="{ color: classOption.direction === 'right' ? 'red' : '' }"
  97. >
  98. 向右滚动
  99. </span>
  100. </el-button>
  101. </div>
  102. <el-link
  103. class="mt-2"
  104. href="https://github.com/pure-admin/vue-pure-admin/blob/main/src/views/components/seamless-scroll.vue"
  105. target="_blank"
  106. >
  107. 代码位置 src/views/components/seamless-scroll.vue
  108. </el-link>
  109. </template>
  110. <SeamlessScroll
  111. ref="scroll"
  112. :data="listData"
  113. :class-option="classOption"
  114. class="warp"
  115. >
  116. <ul class="item">
  117. <li v-for="(item, index) in listData" :key="index">
  118. <span class="title" v-text="item.title" />
  119. </li>
  120. </ul>
  121. </SeamlessScroll>
  122. </el-card>
  123. </el-space>
  124. </template>
  125. <style lang="scss" scoped>
  126. .card-header {
  127. display: flex;
  128. align-items: center;
  129. justify-content: space-between;
  130. span {
  131. margin-right: 20px;
  132. }
  133. }
  134. .warp {
  135. width: 360px;
  136. height: 270px;
  137. margin: 0 auto;
  138. overflow: hidden;
  139. ul {
  140. padding: 0;
  141. margin: 0 auto;
  142. list-style: none;
  143. li,
  144. a {
  145. display: flex;
  146. justify-content: space-between;
  147. height: 30px;
  148. font-size: 15px;
  149. line-height: 30px;
  150. }
  151. }
  152. }
  153. </style>