当前位置:   article > 正文

uniapp中实现瀑布流 短视频页面展示_uniapp短视频模板

uniapp短视频模板

直接上干货
第一部分为结构

  1. <swiper class="list" :current='index' @change="swiperchange" @scrolltolower="onReachBottom">
  2. <swiper-item style="overflow: scroll;" v-for="(item,index) in 2" :key="index">
  3. <view v-for="(item,index) in list " class="list_item" :style="{'--top2':item.top+'px','--left':item.left}">
  4. <view class="" style="background: rgba(0, 0, 0, 0.5);">
  5. <view class="">
  6. <!-- <image class="fm" src="https://api.ccttiot.com/smartmeter/img/static/uGUX2rY4w3ZPvRhrKpWw" mode=""> -->
  7. <image class="fm" :src="item.url" mode="widthFix"></image>
  8. </view>
  9. <view class="wz">
  10. <view class="title">
  11. 的故事吧概念啊啊啊啊啊啊啊
  12. </view>
  13. <view class="xx">
  14. <image class="tx" src="https://api.ccttiot.com/smartmeter/img/static/u8HN5WcA04XMKLsMnr2P"
  15. mode=""></image>
  16. <view class="username">
  17. 皮蛋瘦肉...
  18. </view>
  19. <image class="sc" src="https://api.ccttiot.com/smartmeter/img/static/uQJ3tBEKEmeC4jexhNgK"
  20. mode=""></image>
  21. <view class="dz">
  22. 3056
  23. </view>
  24. </view>
  25. </view>
  26. </view>
  27. <view class="kong" style="width: 100%;height: 20rpx;background-color: transparent;"></view>
  28. </view>
  29. </swiper-item>
  30. </swiper>

第二部分为样式
 

  1. .list {
  2. width: 100%;
  3. margin-top: 36rpx;
  4. display: flex;
  5. justify-content: space-between;
  6. padding-right: 36rpx;
  7. flex-wrap: wrap;
  8. height: 80vh;
  9. overflow: scroll;
  10. box-sizing: border-box;
  11. position: relative;
  12. .list_item:last-of-type{
  13. padding-bottom: 200rpx;
  14. }
  15. .list_item {
  16. width: 326rpx;
  17. box-sizing: border-box;
  18. margin-top: 22rpx;
  19. overflow: hidden;
  20. margin-left: 34rpx;
  21. break-inside: avoid;
  22. position: absolute;
  23. // 设置为变量
  24. top: var(--top2);
  25. left: var(--left);
  26. .fm {
  27. width: 100%;
  28. height: 326rpx;
  29. border-radius: 10rpx;
  30. object-fit: cover;
  31. }
  32. .wz {
  33. padding: 18rpx 16rpx;
  34. padding-top: 0 !important;
  35. box-sizing: border-box;
  36. .title {
  37. font-size: 28rpx;
  38. color: #FFFFFF;
  39. margin-top: 10rpx;
  40. text-align: left;
  41. }
  42. .xx {
  43. display: flex;
  44. margin-top: 12rpx;
  45. align-items: center;
  46. .tx {
  47. width: 32rpx;
  48. height: 32rpx;
  49. border-radius: 50%;
  50. margin-right: 10rpx;
  51. }
  52. .username {
  53. font-size: 24rpx;
  54. color: #FFFFFF;
  55. margin-right: 16rpx;
  56. }
  57. .sc {
  58. width: 25rpx;
  59. height: 24rpx;
  60. margin-right: 8rpx;
  61. }
  62. .dz {
  63. font-size: 24rpx;
  64. color: #FFFFFF;
  65. }
  66. }
  67. }
  68. }
  69. }

第三部分为js部分
 

  1. export default {
  2. data() {
  3. return {
  4. AllData: [],
  5. leftHeight: 0,
  6. rightHeight: 0,
  7. list: [{
  8. url: "https://api.ccttiot.com/smartmeter/img/static/ur3ZXP3az10GilTm9nOV",
  9. left: "50%",
  10. top: "0",
  11. }, {
  12. url: "https://api.ccttiot.com/smartmeter/img/static/uFo3Rj5OC6S3h0RNaZqf",
  13. left: "50%",
  14. top: "0",
  15. }, {
  16. url: "https://api.ccttiot.com/smartmeter/img/static/ur3ZXP3az10GilTm9nOV",
  17. left: "50%",
  18. top: "0",
  19. },
  20. {
  21. url: "https://api.ccttiot.com/smartmeter/img/static/u8HN5WcA04XMKLsMnr2P",
  22. left: "50%",
  23. top: "0",
  24. },
  25. {
  26. url: "https://api.ccttiot.com/smartmeter/img/static/uZQmeK9Fp2oHAnu3Yc3U",
  27. left: "50%",
  28. top: "0",
  29. },
  30. {
  31. url: "https://api.ccttiot.com/smartmeter/img/static/uGUX2rY4w3ZPvRhrKpWw",
  32. left: "50%",
  33. top: "0",
  34. },
  35. {
  36. url: "https://api.ccttiot.com/smartmeter/img/static/uZQmeK9Fp2oHAnu3Yc3U",
  37. left: "50%",
  38. top: "0",
  39. },
  40. {
  41. url: "https://api.ccttiot.com/smartmeter/img/static/u8HN5WcA04XMKLsMnr2P",
  42. left: "50%",
  43. top: "0",
  44. },
  45. {
  46. url: "https://api.ccttiot.com/smartmeter/img/static/uFo3Rj5OC6S3h0RNaZqf",
  47. left: "50%",
  48. top: "0",
  49. },
  50. ],
  51. }
  52. },
  53. onLoad() {
  54. //在页面一开始就获取数据进行操作
  55. setTimeout(() => {
  56. uni.createSelectorQuery().selectAll('.list_item').boundingClientRect(data => {
  57. data.forEach((item) => {
  58. this.AllData.push(item.height)
  59. })
  60. for (let i = 0; i < this.AllData.length; i++) {
  61. // 判断赋值
  62. if (this.rightHeight < this.leftHeight) {
  63. // 设置位置
  64. this.list[i].left = '50%'
  65. // 先进行赋值
  66. this.list[i].top = this.rightHeight
  67. // 再进行累加
  68. this.rightHeight += this.AllData[i]
  69. } else {
  70. this.list[i].left = 0
  71. this.list[i].top = this.leftHeight
  72. this.leftHeight += this.AllData[i]
  73. }
  74. }
  75. }).exec()
  76. }, 500)
  77. },
  78. methods: {
  79. swiperchange(e){
  80. console.log(e.target.current);
  81. this.index = e.target.current
  82. },
  83. }
  84. }
  85. </script>

最后附上效果图  当中我所使用的图片均为线上图片  

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

闽ICP备14008679号