scrollBox.vue 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  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" 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.userName }}刚刚扫描了一个VIN</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. },
  21. data() {
  22. return {
  23. scrollHeight: 0, //向上滚动距离
  24. height: 0, //.lis高度(滚动框高度)
  25. animationData: {} //动画对象
  26. };
  27. },
  28. components: {},
  29. mounted() {
  30. this.prizeScroll();
  31. },
  32. methods: {
  33. getHeight(Class) {
  34. let query = uni.createSelectorQuery().in(this);
  35. query
  36. .selectAll(Class)
  37. .boundingClientRect(data => {
  38. this.height = data[0].height;
  39. })
  40. .exec();
  41. },
  42. prizeScroll() {
  43. let speed = 60;
  44. let animation = uni.createAnimation({
  45. duration: this.getHeight('.lis') / speed,
  46. timingFunction: 'linear',
  47. delay: 0
  48. });
  49. this.animation = animation;
  50. setInterval(() => {
  51. if (this.scrollHeight >= this.height) {
  52. animation.translateY(0).step();
  53. this.scrollHeight = 0;
  54. this.animationData = animation.export();
  55. } else {
  56. this.scrollHeight = this.scrollHeight + 1;
  57. animation.translateY(-this.scrollHeight).step();
  58. this.animationData = animation.export();
  59. }
  60. }, speed);
  61. }
  62. }
  63. };
  64. </script>
  65. <style lang="less">
  66. .list {
  67. width: 50%;
  68. height: 2.6em;
  69. overflow: hidden;
  70. .item{
  71. background: rgba(229, 237, 240, 0.3);
  72. border-radius: 5em;
  73. padding: 0.2em 1em;
  74. font-size: 0.8em;
  75. margin:0.3em 0;
  76. }
  77. }
  78. </style>