WF-scroll.vue 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. <template>
  2. <div>
  3. <scroll-view show-scrollbar="true" :scroll-top="scrollTop" scroll-y="true" @scrolltolower="upper" class="scroll"
  4. @scroll="scroll" :style="{'height':scrollHeight+'rpx'}">
  5. <div class="content" @touchstart="touchstart" @touchend="touchend">
  6. <view class="flex-row justify-between rollItem" v-for="(item,index) in listAr">
  7. <view>
  8. <text class="text2">{{item.createTime}}</text>
  9. <text class="text1">{{item.userName}}</text>
  10. </view>
  11. <view>
  12. <text class="text3">{{item.prizeName}}</text>
  13. <!-- <text class="text2">{{item.prizeName}}</text>-->
  14. </view>
  15. </view>
  16. </div>
  17. </scroll-view>
  18. </div>
  19. </template>
  20. <script>
  21. /*
  22. listAr 循环数组
  23. scrollHeight scroll可视区域高度
  24. scrollTimer 是否默认开始滚动
  25. */
  26. export default {
  27. name: "WF-scroll",
  28. props: {
  29. listAr: {
  30. type: Array,
  31. default () {
  32. return []
  33. }
  34. },
  35. scrollHeight: '',
  36. scrollTimer:'',
  37. },
  38. data() {
  39. return {
  40. scrollTop: 0,
  41. scrollType: true, //判断滚动所用为防止滚动到底部多次赋值
  42. contentHeight: '', //内容高度
  43. touchstartType: false,
  44. };
  45. },
  46. created() {
  47. setTimeout(() => {
  48. if(this.scrollTimer){
  49. this.setTimer()
  50. }
  51. const query = uni.createSelectorQuery().in(this);
  52. query.select('.content').boundingClientRect(data => {
  53. this.contentHeight = data.height * 2 - 40
  54. }).exec();
  55. }, 1000)
  56. },
  57. methods: {
  58. // 手指触摸
  59. touchstart() {
  60. this.touchstartType = true
  61. this.removeTimer()
  62. },
  63. // 手指离开
  64. touchend() {
  65. this.touchstartType = false
  66. this.setTimer()
  67. this.upper()
  68. },
  69. scroll(e) {
  70. if (this.touchstartType) {
  71. this.scrollTop = e.detail.scrollTop
  72. }
  73. },
  74. upper() {
  75. console.log(this.touchstartType);
  76. if (!this.touchstartType) {
  77. setTimeout(() => {
  78. if (this.scrollType && this.contentHeight > this.scrollHeight) {
  79. this.scrollTop = 0
  80. this.scrollType = false
  81. setTimeout(() => {
  82. this.scrollType = true
  83. }, 3000)
  84. }
  85. }, 3000)
  86. }
  87. },
  88. removeTimer() {
  89. if (this.timer) {
  90. clearInterval(this.timer)
  91. this.timer = null
  92. }
  93. },
  94. // 这里设置滚动速度时间越短滚动则越快
  95. setTimer() {
  96. this.removeTimer()
  97. this.timer = setInterval(() => {
  98. this.scrollTop++
  99. }, 44)
  100. },
  101. }
  102. }
  103. </script>
  104. <style scoped lang="scss">
  105. .content {
  106. /*padding-top: 40rpx;*/
  107. /*background: #fff;*/
  108. }
  109. .scroll{
  110. overflow: hidden;
  111. }
  112. .content_list {
  113. overflow: hidden;
  114. white-space: nowrap;
  115. text-overflow: ellipsis;
  116. cursor: pointer;
  117. color: #1debffff;
  118. font-size: 32rpx;
  119. text-align: left;
  120. padding: 20rpx 0;
  121. }
  122. .rollItem{
  123. padding: 0 24rpx;
  124. font-size: 24rpx;
  125. border-bottom: 1px solid #f1f1f1;
  126. line-height: 60rpx;
  127. }
  128. .text1{
  129. margin-left: 10rpx;
  130. }
  131. .text2{
  132. margin-left: 10rpx;
  133. }
  134. .text3{
  135. color: #F56C6C;
  136. }
  137. </style>