小程序移动端 uniapp 排课表 表头固定第一列固定 跟随表体移动

直接代码 着急摸鱼

<template>
	<view class="schedule-container">
		<view style="display: flex;">
			<view class="time-col"></view>
			<scroll-view class="header-scroll" :scroll-left="scrollLeft" scroll-x>
				<view class="header-row">
					<view class="course-col" v-for="(course, index) in courses" :key="index">
						{{ course }}
					</view>
				</view>
			</scroll-view>
		</view>

		<scroll-view class="schedule-scroll" scroll-x scroll-y @scroll="onScheduleScroll">
			<view class="schedule-body">
				<view class="schedule-row" v-for="(timeSlot, index) in timeSlots" :key="index">
					<view class="time-col">
						{{ timeSlot }}
					</view>
					<view class="course-col" v-for="(course, index) in courses" :key="index">
						<view style="height: 100rpx;">{{ course }}1</view>
					</view>
				</view>
			</view>
		</scroll-view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				courses: ['课程1', '课程2', '课程3', '课程4', '课程5'],
				timeSlots: ['时间段1', '时间段2', '时间段3', '时间段4', '时间段5', '时间段5', '时间段5'],
				scrollLeft: 0
			};
		},
		methods: {
			onScheduleScroll(event) {
				this.scrollLeft = event.detail.scrollLeft;
			}
		}
	};
</script>

<style>
	.schedule-container {
		height: 100vh;
		width: 100vw;
		display: flex;
		flex-direction: column;
		overflow: hidden;
	}

	.header-scroll {
		height: 100px;
		overflow-x: scroll;
		overflow-y: hidden;
	}

	.schedule-scroll {
		flex: 1;
		overflow: auto;
	}

	.schedule-body {
		width: max-content;
		white-space: nowrap;
		position: static;
		left: 0;
		top: 100rpx;
	}

	.header-row,
	.schedule-row {
		height: 100%;
		display: flex;
	}

	.time-col,
	.course-col {
		flex: none;
		width: 150px;
		border: 1px solid #ccc;
		padding: 10px;
		text-align: center;
	}

	.time-col {
		background-color: #f5f5f5;
	}

	/* .header-row .time-col {
		width: 150px;
		position: sticky;
		left: 0;
		top: 0;
		background-color: #f5f5f5;
		z-index: 2;
	} */

	.header-row .course-col {
		position: sticky;
		top: 0;
		background-color: #f5f5f5;
		z-index: 1;
	}

	.schedule-row .time-col {
		position: sticky;
		left: 0;
		top: 100rpx;
		height: auto;
		min-height: 100px;
		background-color: #f5f5f5;
		overflow-y: auto;
	}
</style>
  • 2
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值