scrollBox.vue 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <template>
  2. <view class="list uni-flex uni-column">
  3. <view class="wrap-item">
  4. <view class="lis uni-flex uni-column" :animation="animationData">
  5. <view class="uni-flex uni-column item" :style="{background: bgColor,color:color}" v-for="(item, index) in list" :key="index">
  6. <view class="swiper-item item_title uni-flex list_item">
  7. <view class="time uni-flex-item justify-align-center uni-flex">{{ item.placeText }}</view>
  8. </view>
  9. </view>
  10. </view>
  11. </view>
  12. </view>
  13. </template>
  14. <script>
  15. export default {
  16. props: {
  17. list: {
  18. type: Array
  19. },
  20. bgColor: {
  21. type: String,
  22. default: 'rgba(229, 237, 240, 0.6)'
  23. },
  24. color: {
  25. type: String,
  26. default: '#333'
  27. }
  28. },
  29. data() {
  30. return {
  31. scrollHeight: 0, //向上滚动距离
  32. height: 0, //.lis高度(滚动框高度)
  33. animationData: {} //动画对象
  34. };
  35. },
  36. mounted() {
  37. this.prizeScroll();
  38. },
  39. methods: {
  40. getHeight(Class) {
  41. let query = uni.createSelectorQuery().in(this);
  42. query
  43. .selectAll(Class)
  44. .boundingClientRect(data => {
  45. this.height = data[0].height;
  46. })
  47. .exec();
  48. },
  49. prizeScroll() {
  50. let speed = 60;
  51. let animation = uni.createAnimation({
  52. duration: this.getHeight('.lis') / speed,
  53. timingFunction: 'linear',
  54. delay: 0
  55. });
  56. this.animation = animation;
  57. setInterval(() => {
  58. if (this.scrollHeight >= this.height) {
  59. animation.translateY(0).step();
  60. this.scrollHeight = 0;
  61. this.animationData = animation.export();
  62. } else {
  63. this.scrollHeight = this.scrollHeight + 1;
  64. animation.translateY(-this.scrollHeight).step();
  65. this.animationData = animation.export();
  66. }
  67. }, speed);
  68. }
  69. }
  70. };
  71. </script>
  72. <style lang="less">
  73. .list {
  74. width: 60%;
  75. height: 2.6em;
  76. overflow: hidden;
  77. .item{
  78. background: rgba(229, 237, 240, 0.6);
  79. border-radius: 5em;
  80. padding: 0.2em 1em;
  81. font-size: 0.8em;
  82. margin:0.3em 0;
  83. }
  84. }
  85. </style>