userNameSwiper.vue 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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~2021 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. console.log(this.distance)
  57. this.$set(this, 'distance', this.distance - this.width / this.combinationUserList.length)
  58. // 如果位移超过宽度,则回到起点
  59. if (this.distance === -this.width) {
  60. this.init = false
  61. this.distance = 0
  62. setTimeout(e => {
  63. this.init = true
  64. }, 800)
  65. }
  66. }, 2500)
  67. }
  68. },
  69. destroyed() {
  70. clearInterval(this.timer);
  71. this.timer = null;
  72. },
  73. deactivated() {
  74. clearInterval(this.timer);
  75. this.timer = null;
  76. }
  77. }
  78. </script>
  79. <style lang="scss" scoped>
  80. .user-swiper {
  81. width: 260rpx;
  82. overflow: hidden;
  83. border-radius: 25rpx;
  84. background: rgba(#000000, 0.3);
  85. height: 50rpx;
  86. display: flex;
  87. align-items: center;
  88. .box {
  89. width: max-content;
  90. display: flex;
  91. align-items: center;
  92. flex-wrap: nowrap;
  93. transition: all .8s;
  94. .user-list {
  95. display: flex;
  96. align-items: center;
  97. justify-content: center;
  98. width: 260rpx;
  99. border-radius: 25rpx;
  100. padding: 8rpx 18rpx;
  101. color: #fff;
  102. font-size: 22rpx;
  103. .header-img {
  104. width: 34rpx;
  105. height: 34rpx;
  106. border-radius: 50%;
  107. border: 1px solid #FFFFFF;
  108. margin-right: 6rpx;
  109. }
  110. }
  111. }
  112. }
  113. </style>