当前位置: 首页 > article >正文

uniapp实现首行首列冻结效果

uniapp首行首列冻结

<template>
	<view class="height800 flex-column absolute bgc-withe">

		<!-- 第一行 -->
		<view class="flex diy-header">
			<view class="box">时间</view>
			<scroll-view id="1" enable-flex="true" scroll-x="true" :scroll-left="scrollLeft" class="diy-header-title flex relative scroll-view-x"
				ref="xScroll" @scroll="handleScrollX">
				<view class="box" v-for="(colum,indexItem) in colums" :key="indexItem">{{colum}}</view>
			</scroll-view>

		</view>
		<!-- 下面整块 -->
		<view class="flex diy-body">
			<view class="flex">
				<scroll-view id='timesColum' scroll-y="true" :scroll-top="scrollTop" show-scrollbar=false class="flex-column scroll-view-y" ref="yScroll"
					@scroll="handleScrollY">
					<view class="box" v-for="(time,index) in times" :key="index">{{time}}</view>
				</scroll-view>
				<scroll-view scroll-y="true" :scroll-top="scrollTop" id="timesAndDateColum" class="flex-column scroll-view-y" ref="yScroll"
					@scroll="handleScrollY">
					<scroll-view enable-flex="true" scroll-x="true" :scroll-left="scrollLeft" class="flex diy-body-row scroll-view-x"
						ref="xScroll" @scroll="handleScrollX" v-for="(time,index) in times" :key="index">
						<view class="box" v-for="(colum,indexItem) in colums" :key="indexItem" :class="{'active':activeTimeAndColum===`${index}-${indexItem}`}" @click="selectTimeAndColum(index,indexItem)">{{time}}--{{colum}}
						</view>
					</scroll-view>
				</scroll-view>
			</view>


		</view>




	</view>
</template>

<script>
	export default {
		data() {
			const colums = ['A1', 'A2', 'A3', 'A4', 'A5', 'A6', 'A7', 'A8'];
			const times = ['9:00', '10:00', '11:00', '12:00', '13:00', '14:00', '15:00', '16:00', '17:00', '18:00',
				'19:00', '20:00'
			];
			const scrollTop=0;
			const scrollLeft=0;
			const activeIndex=-1;
			const activeIndexItem=-1;
			const activeTimeAndColum='';
			
			return {
				//时间列
				times,
				//场馆列
				colums,
				// 竖直滚动条位置 :scroll-top="scrollTop"动态绑定属性,调整位置,所有的竖直滚动条会跟着一起变化
				scrollTop,
				// 水平滚动条位置
				scrollLeft,
				//激活的时间索引列
				activeIndex,
				//激活的场馆索引列
				activeIndexItem,
				//标记元素的唯一标识
				activeTimeAndColum
			}
		},
		methods: {
			handleScrollX(e) {
				this.scrollLeft=e.detail.scrollLeft
			},
			handleScrollY(e) {
				this.scrollTop=e.detail.scrollTop
			},selectTimeAndColum(index,indexItem){
				this.activeIndex=index;
				this.activeIndexItem=indexItem;
				this.activeTimeAndColum=index+'-'+indexItem;
			}
		}
	}
</script>

<style>
	.height800 {
		height: 800rpx;
	}

	.flex {
		display: flex;
		overflow-x: auto;
	}

	.flex-column {
		display: flex;
		flex-direction: column;
		overflow-y: auto;
	}

	#timesColum {
		width: 198rpx;
	}

	.box {
		width: 150rpx;
		height: 100rpx;
		line-height: 100rpx;
		border: 1rpx soild black;
		text-align: center;
		/* 不伸缩,固定宽度 */
		flex: 0 0 auto;
	}

	.absolute {
		position: absolute;
	}

	.relative {
		position: relative;
	}

	.diy-header {
		position: relative;
		left: 0rpx;
		top: 0rpx;
		/* 不伸缩,固定宽度 */
		flex: 0 0 auto;
	}

	.diy-header-title {
		width: 450rpx;
	}

	.diy-body-row {
		/* 不伸缩,固定宽度 */
		flex: 0 0 auto;
		width: 450rpx;
	}

	.diy-body {
		position: relative;
		top: 0rpx;
		left: 0rpx;
	}

	.bgc-withe {
		background-color: #ffffff;
	}

	scroll-view.flex {
		height: 100rpx !important;
	}
	::-webkit-scrollbar{
		/* 隐藏滚动条 */
		display: none;
	}
	.box.active{
		background-color: #4CAF50;
		color: #ffffff;
	}
</style>

http://www.kler.cn/a/546394.html

相关文章:

  • 能源物联网数据采集网关 多协议对接解决方案
  • 代码随想录算法营Day38 | 62. 不同路径,63. 不同路径 II,343. 整数拆分,96. 不同的二叉搜索树
  • ICLR2022 | IAA | 从数据分布的角度重新思考对抗转移性
  • Qt接入deepseekv3 API 提供openssl 1.1.1g安装包
  • win11 MBR 启动 如何把我的硬盘改 GPT win11 的 UEFI 启动
  • Vulhub靶机 ActiveMQ任意 文件写入(CVE-2016-3088)(渗透测试详解)
  • 使用爬虫获取1688商品分类:实战案例指南
  • PMP冲刺每日一题(8)
  • Java 语言深度剖析与实践应用
  • 一文深入了解DeepSeek-R1:模型架构
  • Baumer工业相机堡盟工业相机如何通过NEOAPI SDK实现一次触发控制三个光源开关分别采集三张图像(C#)
  • 基础网络详解4--HTTP CookieSession 思考 2
  • S4D480 S4HANA 基于PDF的表单打印
  • FFmpeg中时长的表示方式
  • 论文笔记:Multi-Head Mixture-of-Experts
  • 数据库开发常识(10.6)——考量使用临时表及表连接写法(3)
  • 聊一聊FutureTask源码中体现的“自旋锁”思想
  • 10G EPON光模块
  • 【Matlab算法】基于人工势场的多机器人协同运动与避障算法研究(附MATLAB完整代码)
  • 交叉编译foxy版ros2部署到ARM上运行