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

news/2024/7/8 12:08:03 标签: uni-app, 音视频, 前端

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

<swiper class="list" :current='index' @change="swiperchange" @scrolltolower="onReachBottom">
			<swiper-item style="overflow: scroll;" v-for="(item,index) in 2" :key="index">
					<view v-for="(item,index) in list " class="list_item" :style="{'--top2':item.top+'px','--left':item.left}">
                        <view class="" style="background: rgba(0, 0, 0, 0.5);">
                        	<view class="">
                        		<!-- <image class="fm" src="https://api.ccttiot.com/smartmeter/img/static/uGUX2rY4w3ZPvRhrKpWw" mode=""> -->
                        		<image class="fm" :src="item.url" mode="widthFix"></image>
                        	</view>
                        	<view class="wz">
                        		<view class="title">
                        			的故事吧概念啊啊啊啊啊啊啊
                        		</view>
                        		<view class="xx">
                        			<image class="tx" src="https://api.ccttiot.com/smartmeter/img/static/u8HN5WcA04XMKLsMnr2P"
                        				mode=""></image>
                        			<view class="username">
                        				皮蛋瘦肉...
                        			</view>
                        			<image class="sc" src="https://api.ccttiot.com/smartmeter/img/static/uQJ3tBEKEmeC4jexhNgK"
                        				mode=""></image>
                        			<view class="dz">
                        				3056
                        			</view>
                        		</view>
                        	</view>
                        </view>
						<view class="kong" style="width: 100%;height: 20rpx;background-color: transparent;"></view>
					</view>
			</swiper-item>
		</swiper>


第二部分为样式
 

		.list {
			width: 100%;
			margin-top: 36rpx;
			display: flex;
			justify-content: space-between;
			padding-right: 36rpx;
			flex-wrap: wrap;
			height: 80vh;
			overflow: scroll;
			box-sizing: border-box;
		    position: relative;
			.list_item:last-of-type{
				padding-bottom: 200rpx;
			}
			.list_item {
				width: 326rpx;
				box-sizing: border-box;
				margin-top: 22rpx;
				overflow: hidden;
		        margin-left: 34rpx; 
				break-inside: avoid;
				position: absolute;
				// 设置为变量
				top: var(--top2);
				left: var(--left);
				.fm {
					width: 100%;
					height: 326rpx;
					border-radius: 10rpx;
					object-fit: cover;
				}
		
				.wz {
					padding: 18rpx 16rpx;
					padding-top: 0 !important;
					box-sizing: border-box;
		
					.title {
						font-size: 28rpx;
						color: #FFFFFF;
						margin-top: 10rpx;
						text-align: left;
					}
		
					.xx {
						display: flex;
						margin-top: 12rpx;
						align-items: center;
		
						.tx {
							width: 32rpx;
							height: 32rpx;
							border-radius: 50%;
							margin-right: 10rpx;
						}
		
						.username {
							font-size: 24rpx;
							color: #FFFFFF;
							margin-right: 16rpx;
						}
		
						.sc {
							width: 25rpx;
							height: 24rpx;
							margin-right: 8rpx;
						}
		
						.dz {
							font-size: 24rpx;
							color: #FFFFFF;
						}
					}
				}
		
			}
		}

第三部分为js部分
 

export default {
		data() {
			return {
				AllData: [],
				leftHeight: 0,
				rightHeight: 0,
				list: [{
						url: "https://api.ccttiot.com/smartmeter/img/static/ur3ZXP3az10GilTm9nOV",
						left: "50%",
						top: "0",
					}, {
						url: "https://api.ccttiot.com/smartmeter/img/static/uFo3Rj5OC6S3h0RNaZqf",
						left: "50%",
						top: "0",
					}, {
						url: "https://api.ccttiot.com/smartmeter/img/static/ur3ZXP3az10GilTm9nOV",
						left: "50%",
						top: "0",
					},
					{
						url: "https://api.ccttiot.com/smartmeter/img/static/u8HN5WcA04XMKLsMnr2P",
						left: "50%",
						top: "0",
					},
					{
						url: "https://api.ccttiot.com/smartmeter/img/static/uZQmeK9Fp2oHAnu3Yc3U",
						left: "50%",
						top: "0",
					},
					{
						url: "https://api.ccttiot.com/smartmeter/img/static/uGUX2rY4w3ZPvRhrKpWw",
						left: "50%",
						top: "0",
					},
					{
						url: "https://api.ccttiot.com/smartmeter/img/static/uZQmeK9Fp2oHAnu3Yc3U",
						left: "50%",
						top: "0",
					},
					{
						url: "https://api.ccttiot.com/smartmeter/img/static/u8HN5WcA04XMKLsMnr2P",
						left: "50%",
						top: "0",
					},
					{
						url: "https://api.ccttiot.com/smartmeter/img/static/uFo3Rj5OC6S3h0RNaZqf",
						left: "50%",
						top: "0",
					},
				],
				

			}
		},
		onLoad() {
            //在页面一开始就获取数据进行操作
			setTimeout(() => {
				uni.createSelectorQuery().selectAll('.list_item').boundingClientRect(data => {
					data.forEach((item) => {
						this.AllData.push(item.height)
					})
					for (let i = 0; i < this.AllData.length; i++) {
						// 判断赋值
						if (this.rightHeight < this.leftHeight) {
							// 设置位置
							this.list[i].left = '50%'
							// 先进行赋值
							this.list[i].top = this.rightHeight
							// 再进行累加
							this.rightHeight += this.AllData[i]
						} else {
							this.list[i].left = 0
							this.list[i].top = this.leftHeight
							this.leftHeight += this.AllData[i]
						}
					}
				}).exec()
			}, 500)
		},
		methods: {
			swiperchange(e){
				console.log(e.target.current);
				this.index = e.target.current
			},
		}
	}
</script>

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


http://www.niftyadmin.cn/n/5537187.html

相关文章

网络安全筑基篇——反序列化漏洞

目录 序列化是什么&#xff1f; 反序列化又是什么&#xff1f; 反序列化漏洞的危害 代码样例 常见的魔术方法 修复方式有哪些&#xff1f; 常见的反序列化漏洞 Shiro反序列化漏洞 Fastjson反序列化漏洞 序列化是什么&#xff1f; 将实例化对象转换成字节流的过程 反序…

矩阵运算在数据分析中的应用

矩阵运算在数据分析中的应用 大家好&#xff0c;我是免费搭建查券返利机器人省钱赚佣金就用微赚淘客系统3.0的小编&#xff0c;也是冬天不穿秋裤&#xff0c;天冷也要风度的程序猿&#xff01; 矩阵运算作为数学和计算机科学中的重要概念&#xff0c;在数据分析和科学计算中发…

类和对象-C++运算符重载-加号运算符重载

加号运算符重载 1、成员函数重载号 #include<iostream>using namespace std;class Person { public://1、成员函数重载号Person operator(Person &p){Person temp;temp.m_Athis->m_Ap.m_A;temp.m_Bthis->m_Bp.m_B;return temp; }int m_A;int m_B; }; void t…

【数据集】中国农田栅格数据CACD(1986-2021)

中国农田栅格数据(1986-2021) 数据概述数据下载参考精确、详细和及时的耕地范围信息对于保障食品安全和环境可持续性至关重要。然而,由于农业景观的复杂性以及缺乏足够的训练样本,要在大范围地理区域内高空间和时间分辨率下监测耕地动态仍然具有挑战性,特别是对于农业土地…

自动化革新者:PlugLink在“智创设计”中的实战应用

PlugLink&#xff1a;小微企业运营自动化的新引擎 在当今竞争激烈的市场环境下&#xff0c;小微企业要想脱颖而出&#xff0c;除了要有敏锐的市场洞察力&#xff0c;还需具备高效灵活的运营能力。本文将通过一个生动的实例&#xff0c;揭示开源项目PlugLink如何助力一家名为“…

Selenium 等待

环境&#xff1a; Python 3.8 selenium3.141.0 urllib31.26.19 Chromium 109.0.5405.0 &#xff08;32 位&#xff09; # 1 固定等待&#xff08;time&#xff09; # 固定待是利用python语言自带的time库中的sleep()方法&#xff0c;固定等待几秒。 # 这种方式会导致这个脚本运…

nginx配置stream代理

项目中遇到某些服务在内网&#xff0c;需要外网访问的情况&#xff0c;需要配置代理访问。可用nginx搭建代理服务。 TCP代理 通过nginx的stream模块可以直接代理TCP服务&#xff0c;步骤如下&#xff1a; 在/etc/nginx/下新建proxy文件夹&#xff0c;用于存放代理配置。此处…

代码技巧专题 -- 使用策略模式编写HandleService

一.前言 最近项目有实习的同事加入&#xff0c;很多实习同事反映&#xff0c;看不懂项目中的一些使用了设计模式的代码&#xff0c;比如HandleService&#xff0c;Chains&#xff0c;Listener等。本篇就介绍一下策略模式在项目中的使用&#xff0c;也就是我们常在项目中看到的X…