noticeBar.vue 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. <template>
  2. <!-- 无缝滚动效果 -->
  3. <view class="marquee-wrap">
  4. <view class="marquee-list" :class="{'animate-up': animateUp}">
  5. <view class="marquee-item" v-for="(item, index) in listData" :key="item.id">
  6. {{ prefix }}<text class="name">{{ item.user ? item.user.nickname : '****' }}</text>获得<text>{{ item.prize.name }}</text>
  7. </view>
  8. </view>
  9. </view>
  10. </template>
  11. <script>
  12. export default {
  13. name: "noticeBar",
  14. data() {
  15. return {
  16. animateUp: false,
  17. listData: JSON.parse(JSON.stringify(this.showMsg)),
  18. timer: null
  19. }
  20. },
  21. props: {
  22. showMsg: {
  23. type: Array
  24. },
  25. prefix: {
  26. type: String
  27. },
  28. },
  29. mounted() {
  30. this.timer = setInterval(this.scrollAnimate, 2500);
  31. },
  32. methods: {
  33. scrollAnimate() {
  34. this.animateUp = true
  35. setTimeout(() => {
  36. this.listData.push(this.listData[0])
  37. this.listData.shift()
  38. this.animateUp = false
  39. }, 500)
  40. }
  41. },
  42. destroyed() {
  43. clearInterval(this.timer)
  44. }
  45. };
  46. </script>
  47. <style lang="scss" scoped>
  48. .marquee-wrap {
  49. width: 100%;
  50. height: 40rpx;
  51. border-radius: 20px;
  52. margin: 0 auto;
  53. overflow: hidden;
  54. .marquee-list {
  55. padding: 0;
  56. .marquee-item {
  57. width: 100%;
  58. height: 100%;
  59. text-overflow: ellipsis;
  60. overflow: hidden;
  61. white-space: nowrap;
  62. padding: 0;
  63. list-style: none;
  64. line-height: 40rpx;
  65. // text-align: center;
  66. color: #fff;
  67. font-size: 26rpx;
  68. font-weight: 400;
  69. }
  70. .name {
  71. color: #FFEF6C;
  72. }
  73. }
  74. .animate-up {
  75. transition: all 0.5s ease-in-out;
  76. // transform: translateY(-40rpx);
  77. margin-top: -40rpx;
  78. }
  79. }
  80. </style>