barrage.vue 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. <template>
  2. <view class="wrapper" :style="{ paddingLeft: left + 'px' }">
  3. <view class="scroll-content" :animation="animationData" @transitionend="animalEnd">
  4. <view class="item" v-for="(item, index) in data" :key="index">
  5. <view class="avatarBox">
  6. <image :src="item.avatar" class="avatar" />
  7. <image :src="item.cover" class="product" />
  8. </view>
  9. <view class="context" style="display: inline-block">
  10. <view class="flex-align">
  11. <text class="text">{{ item.nickname }}购买了</text>
  12. <text :style="{ color: LEVEL_MAP[item.level].color }" class="marginX2">
  13. {{ LEVEL_MAP[item.level].title }}
  14. </text>
  15. </view>
  16. </view>
  17. </view>
  18. </view>
  19. </view>
  20. </template>
  21. <script>
  22. import { LEVEL_MAP } from '@/utils/config'
  23. export default {
  24. props: {
  25. left: {
  26. type: Number,
  27. default: 0
  28. }
  29. },
  30. data() {
  31. return {
  32. data: null,
  33. data1: null,
  34. data2: null,
  35. LEVEL_MAP,
  36. animationData: null
  37. }
  38. },
  39. created() {
  40. this.animation = wx.createAnimation({
  41. timingFunction: 'linear'
  42. })
  43. },
  44. beforeDestroy() {
  45. this.animation = null
  46. this.animationData = null
  47. },
  48. methods: {
  49. start(value) {
  50. let length = value.length
  51. this.data1 = value.slice(0, length / 2)
  52. this.data2 = value.slice(length / 2 + 1, length + 1)
  53. this.data = value
  54. this.$nextTick(() => {
  55. this.startAnimal()
  56. })
  57. },
  58. startAnimal() {
  59. this.animation.translateX(0).step({
  60. duration: 0
  61. })
  62. this.animationData = this.animation.export()
  63. setTimeout(() => {
  64. const lenght = this.data1.length
  65. this.animation.translateX(-lenght * 100).step({
  66. duration: lenght * 2000
  67. })
  68. this.animationData = this.animation.export()
  69. }, 100)
  70. },
  71. animalEnd() {
  72. this.startAnimal()
  73. }
  74. }
  75. }
  76. </script>
  77. <style lang="scss" scoped>
  78. .wrapper {
  79. position: relative;
  80. width: 100%;
  81. overflow: hidden;
  82. }
  83. .scroll-content {
  84. position: relative;
  85. white-space: nowrap;
  86. width: 100%;
  87. }
  88. .item {
  89. display: inline-block;
  90. margin-left: 10rpx;
  91. border-radius: 30rpx;
  92. background: rgba($color: #ffffff, $alpha: 0.4);
  93. // border: 1rpx solid rgba(255, 255, 255, 0.2);
  94. overflow: hidden;
  95. padding: 8rpx;
  96. .avatarBox {
  97. position: relative;
  98. width: 60rpx;
  99. display: inline-block;
  100. }
  101. .avatar {
  102. width: 48rpx;
  103. height: 48rpx;
  104. border-radius: 24rpx;
  105. margin-left: -2rpx;
  106. display: inline-block;
  107. vertical-align: middle;
  108. }
  109. .product {
  110. width: 36rpx;
  111. height: 36rpx;
  112. background: #ffffff;
  113. border-radius: 50%;
  114. position: absolute;
  115. right: 0rpx;
  116. bottom: 0;
  117. }
  118. .context {
  119. padding: 0 20rpx;
  120. color: rgba(0, 0, 0, 0.4);
  121. font-size: 20rpx;
  122. .text {
  123. opacity: 0.7;
  124. }
  125. }
  126. }
  127. </style>