marquee.uvue 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <template>
  2. <cl-page>
  3. <view class="p-3">
  4. <demo-item :label="t('横向滚动')">
  5. <cl-marquee
  6. :list="list"
  7. direction="horizontal"
  8. :item-height="200"
  9. :item-width="360"
  10. :pt="{
  11. className: 'h-[200rpx] rounded-xl'
  12. }"
  13. ></cl-marquee>
  14. </demo-item>
  15. <demo-item :label="t('纵向滚动')">
  16. <cl-marquee
  17. ref="marqueeRef"
  18. :list="list"
  19. direction="vertical"
  20. :item-height="260"
  21. :duration="isSpeed ? 2000 : 5000"
  22. :pt="{
  23. className: 'h-[500rpx] rounded-xl'
  24. }"
  25. ></cl-marquee>
  26. <cl-list
  27. border
  28. :pt="{
  29. className: 'mt-5'
  30. }"
  31. >
  32. <cl-list-item :label="t('快一点')">
  33. <cl-switch v-model="isSpeed"></cl-switch>
  34. </cl-list-item>
  35. <cl-list-item :label="t('暂停')">
  36. <cl-switch v-model="isPause" @change="onPauseChange"></cl-switch>
  37. </cl-list-item>
  38. </cl-list>
  39. </demo-item>
  40. </view>
  41. </cl-page>
  42. </template>
  43. <script lang="ts" setup>
  44. import DemoItem from "../components/item.uvue";
  45. import { t } from "@/locale";
  46. import { ref } from "vue";
  47. const marqueeRef = ref<ClMarqueeComponentPublicInstance | null>(null);
  48. const list = ref<string[]>([
  49. "https://unix.cool-js.com/images/demo/bg1.png",
  50. "https://unix.cool-js.com/images/demo/bg2.png",
  51. "https://unix.cool-js.com/images/demo/bg3.png"
  52. ]);
  53. const isSpeed = ref(false);
  54. const isPause = ref(false);
  55. function onPauseChange(value: boolean) {
  56. if (value) {
  57. marqueeRef.value!.pause();
  58. } else {
  59. marqueeRef.value!.play();
  60. }
  61. }
  62. </script>