scrollBox.vue 1.7 KB

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