noticeBar.vue 1.4 KB

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