userNameSwiper.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. <template>
  2. <view class="user-swiper">
  3. <view class="box" id="box" :style="{marginLeft: `${distance}px`}">
  4. <view class="user-list" v-for="(item,index) in combinationUserList" :key="index">
  5. <image v-show="init" class="header-img" :src="item.avatar ? item.avatar : '/static/images/f.png'" mode=""></image>
  6. <text v-show="init" class="user-name">***** 拼团成功</text>
  7. </view>
  8. </view>
  9. </view>
  10. </template>
  11. <script>
  12. // +----------------------------------------------------------------------
  13. // | CRMEB [ CRMEB赋能开发者,助力企业发展 ]
  14. // +----------------------------------------------------------------------
  15. // | Copyright (c) 2016~2024 https://www.crmeb.com All rights reserved.
  16. // +----------------------------------------------------------------------
  17. // | Licensed CRMEB并不是自由软件,未经许可不能去掉CRMEB相关版权
  18. // +----------------------------------------------------------------------
  19. // | Author: CRMEB Team <admin@crmeb.com>
  20. // +----------------------------------------------------------------------
  21. export default {
  22. data() {
  23. return {
  24. init: true,
  25. distance: 0,
  26. boxWidth: 0,
  27. timer: null // 定时器名称
  28. }
  29. },
  30. props: {
  31. combinationUserList: {
  32. type: Array,
  33. default: () => {
  34. []
  35. }
  36. }
  37. },
  38. watch: {
  39. combinationUserList() {
  40. setTimeout(e => {
  41. const query = uni.createSelectorQuery().in(this);
  42. query.select('#box').boundingClientRect(data => {
  43. this.width = data.width
  44. this.move()
  45. }).exec();
  46. }, 1000)
  47. }
  48. },
  49. activated() {
  50. this.move()
  51. },
  52. methods: {
  53. move() {
  54. // 设置位移
  55. this.timer = setInterval(() => {
  56. this.$set(this, 'distance', this.distance - this.width / this.combinationUserList.length)
  57. // 如果位移超过宽度,则回到起点
  58. if (this.distance === -this.width) {
  59. this.init = false
  60. this.distance = 0
  61. setTimeout(e => {
  62. this.init = true
  63. }, 800)
  64. }
  65. }, 2500)
  66. }
  67. },
  68. destroyed() {
  69. clearInterval(this.timer);
  70. this.timer = null;
  71. },
  72. deactivated() {
  73. clearInterval(this.timer);
  74. this.timer = null;
  75. }
  76. }
  77. </script>
  78. <style lang="scss" scoped>
  79. .user-swiper {
  80. width: 260rpx;
  81. overflow: hidden;
  82. border-radius: 25rpx;
  83. background: rgba(#000000, 0.3);
  84. height: 50rpx;
  85. display: flex;
  86. align-items: center;
  87. .box {
  88. width: max-content;
  89. display: flex;
  90. align-items: center;
  91. flex-wrap: nowrap;
  92. transition: all .8s;
  93. .user-list {
  94. display: flex;
  95. align-items: center;
  96. justify-content: center;
  97. width: 260rpx;
  98. border-radius: 25rpx;
  99. padding: 8rpx 18rpx;
  100. color: #fff;
  101. font-size: 22rpx;
  102. .header-img {
  103. width: 34rpx;
  104. height: 34rpx;
  105. border-radius: 50%;
  106. border: 1px solid #FFFFFF;
  107. margin-right: 6rpx;
  108. }
  109. }
  110. }
  111. }
  112. </style>