• 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="item.url" mode="widthFix">image>
    7. view>
    8. <view class="wz">
    9. <view class="title">
    10. 的故事吧概念啊啊啊啊啊啊啊
    11. view>
    12. <view class="xx">
    13. <image class="tx" src="https://api.ccttiot.com/smartmeter/img/static/u8HN5WcA04XMKLsMnr2P"
    14. mode="">image>
    15. <view class="username">
    16. 皮蛋瘦肉...
    17. view>
    18. <image class="sc" src="https://api.ccttiot.com/smartmeter/img/static/uQJ3tBEKEmeC4jexhNgK"
    19. mode="">image>
    20. <view class="dz">
    21. 3056
    22. view>
    23. view>
    24. view>
    25. view>
    26. <view class="kong" style="width: 100%;height: 20rpx;background-color: transparent;">view>
    27. view>
    28. swiper-item>
    29. 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. }

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

  • 相关阅读:
    青阳网络文件传输系统 kiftd 1.1.0 正式发布!
    Anaconda虚拟环境配置Python库与Spyder编译器
    Qt重定向QDebug,Qt/C++开源作品39-日志输出增强版V2022
    C#【汇总篇】我在VS中编写C#代码常用的几个快捷键
    7.git冲突的产生与解决
    Unity - Rigidbody刚体
    HttpRunnerManager安装(一)
    skywalking springgateway 全链路
    linux发行版CentOS、Debian和Ubuntu的对比
    主成分分析笔记
  • 原文地址:https://blog.csdn.net/m0_74170441/article/details/140042118