当前位置:   article > 正文

uni-app 列表消息滚动的实现_uniapp 消息弹框滚动

uniapp 消息弹框滚动

一、插件下载地址:https://ext.dcloud.net.cn/plugin?id=1179

二、将插件里面的common文件复制到自己项目中去,在自己项目中App.vue中引入css(@import 'common/uni.css';)

三、将tony-scroll.vue实例复制到自己项目页面去使用即可得到滚动效果

示例代码:

  1. <template>
  2. <view class="home">
  3. <view class="list uni-flex uni-column">
  4. <view class="wrap-item">
  5. <view class="lis uni-flex uni-column" :animation="animationData">
  6. <view class="uni-flex uni-column" v-for="(item, index) in list" :key="index">
  7. <view class="swiper-item item_title uni-flex list_item">
  8. <view class="userlistmsg" :class="index%2?'cor':'non'">
  9. <view>{{ item.time }}</view>
  10. <view>{{ item.phone }}</view>
  11. <view>{{ item.prize }}</view>
  12. </view>
  13. </view>
  14. </view>
  15. </view>
  16. </view>
  17. </view>
  18. </view>
  19. </template>
  20. <script>
  21. export default {
  22. data() {
  23. return {
  24. list: [{
  25. time: '陈先生1',
  26. phone: '201903.1',
  27. prize: '领取成功'
  28. },
  29. {
  30. time: '陈先生2',
  31. phone: '201903.1',
  32. prize: '领取成功'
  33. },
  34. {
  35. time: '陈先生3',
  36. phone: '201903.1',
  37. prize: '领取成功'
  38. },
  39. {
  40. time: '陈先生4',
  41. phone: '201903.1',
  42. prize: '领取成功'
  43. },
  44. {
  45. time: '陈先生5',
  46. phone: '201903.1',
  47. prize: '领取成功'
  48. },
  49. {
  50. time: '陈先生6',
  51. phone: '201903.1',
  52. prize: '领取成功'
  53. }
  54. ],
  55. scrollHeight: 0, //向上滚动距离
  56. height: 0, //.lis高度(滚动框高度)
  57. animationData: {} ,//动画对象
  58. }
  59. },
  60. components: {},
  61. mounted() {
  62. console.log("11")
  63. this.prizeScroll();
  64. },
  65. methods: {
  66. getHeight(Class) {
  67. let query = uni.createSelectorQuery().in(this);
  68. query
  69. .selectAll(Class)
  70. .boundingClientRect(data => {
  71. this.height = data[0].height;
  72. })
  73. .exec();
  74. },
  75. prizeScroll() {
  76. let speed = 50;
  77. let animation = uni.createAnimation({
  78. duration: this.getHeight('.lis') / speed,
  79. timingFunction: 'linear',
  80. delay: 0
  81. });
  82. this.animation = animation;
  83. setInterval(() => {
  84. if (this.scrollHeight >= this.height) {
  85. animation.translateY(0).step();
  86. this.scrollHeight = 0;
  87. this.animationData = animation.export();
  88. } else {
  89. this.scrollHeight = this.scrollHeight + 1;
  90. animation.translateY(-this.scrollHeight).step();
  91. this.animationData = animation.export();
  92. }
  93. }, speed);
  94. }
  95. }
  96. };
  97. </script>
  98. <style>
  99. page{
  100. width: 100%;
  101. }
  102. .home,.list {
  103. width: 750upx;
  104. padding-top: 30upx;
  105. }
  106. .userlistmsg{
  107. width: 100%;
  108. display: flex;
  109. justify-content: space-around;
  110. }
  111. .cor{
  112. background: #FFF5F3 ;
  113. }
  114. </style>

 

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/酷酷是懒虫/article/detail/1015696
推荐阅读
相关标签