uniapp 实现固定顶部view,内容可滑动

<template>
	<view class="container">
		<view>
			<!--搜索栏-->
			<uni-search-bar @confirm="search" :focus="true" v-model="searchValue" @blur="blur" @focus="focus"
				@input="input" @cancel="cancel" @clear="clear" placeholder="培训名称">
			</uni-search-bar>
			<!--选项卡-->
			<view class="tabBox">
				<view :class="['defaultTab',tabId==0?'selectTab':'']" @click="tabId=0">待开课</view>
				<view :class="['defaultTab',tabId==1?'selectTab':'']" @click="tabId=1">已结束</view>
			</view>
		</view>
		<view class="body">
			<!--待开课-->
			<view v-show="tabId == 0">
				<view class="row_content" v-for="(item,index) in array" :key="index">
					<image src="/static/px.png" class="big_img"></image>
					<view class="detail">
						<view class="course_name">课程名称:{{item.name}}</view>
						<view class="time">开始时间:{{item.start}}</view>
						<view class="time">结束时间:{{item.end}}</view>
					</view>
					<view class="centerLay lower_right">
						<view class="centerLay small-box line">
							<image src="/static/px_qj.png" class="small_img"></image>
							<text>请假</text>
						</view>
						<view class="centerLay small-box">
							<image src="/static/px_kj.png" class="small_img"></image>
							<text>课件</text>
						</view>
					</view>
				</view>
			</view>
			<!--待开课end-->
			<!--已结束-->
			<view v-show="tabId == 1">
				<view class="row_content" v-for="(item,index) in array" :key="index">
					<image src="/static/px.png" class="big_img"></image>
					<view class="detail">
						<view class="course_name">课程名称:{{item.name}}</view>
						<view class="time">开始时间:{{item.start}}</view>
						<view class="time">结束时间:{{item.end}}</view>
					</view>
					<view class="centerLay lower_right">
						<view class="centerLay small-box">
							<image src="/static/px_kj.png" class="small_img"></image>
							<text>课件</text>
						</view>
					</view>
				</view>
			</view>
			<!--已结束end-->
		</view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				tabId: 0,
				searchValue: '',
				array: [{
						name: 'PMS项目管理',
						start: "2023-07-30 11:00",
						end: "2023-07-30 12:00"
					},
					{
						name: '安全生产,职业健康知识培训',
						start: "2023-07-30 11:00",
						end: "2023-07-30 11:00"
					},
					{
						name: '职业健康知识培训',
						start: "2023-07-30 11:00",
						end: "2023-07-30 11:00"
					},
					{
						name: '安全生产知识培训',
						start: "2023-07-30 11:00",
						end: "2023-07-30 11:00"
					},
				]
			}
		},
		methods: {
			changeTab(tabId) {
				that.navIdx = tabId;
			},
			search(res) {
				uni.showToast({
					title: '搜索:' + res.value,
					icon: 'none'
				})
			},
			input(res) {
				console.log('----input:', res)
			},
			clear(res) {
				uni.showToast({
					title: 'clear事件,清除值为:' + res.value,
					icon: 'none'
				})
			},
			blur(res) {
				uni.showToast({
					title: 'blur事件,输入值为:' + res.value,
					icon: 'none'
				})
			},
			focus(e) {
				uni.showToast({
					title: 'focus事件,输出值为:' + e.value,
					icon: 'none'
				})
			},
			cancel(res) {
				uni.showToast({
					title: '点击取消,输入值为:' + res.value,
					icon: 'none'
				})
			}
		}
	}
</script>

<style>
	page {
		display: -webkit-box;
		width: 100%;
		height: 100%;
	}

	.container {
		width: 100%;
		min-height: 100vh;
		display: flex;
		flex-direction: column;
	}

	.body {
		overflow-y: scroll;
	}

	.centerLay {
		display: flex;
		align-items: center;
		justify-content: center;
	}

	.tabBox {
		background-color: #FFFFFF;
		height: 100rpx;
		display: flex;
	}

	.defaultTab {
		font-size: 30rpx;
		flex: 1;
		text-align: center;
		color: #C9C9C9;
		height: 100rpx;
		line-height: 100rpx;
	}

	.selectTab {
		font-weight: bold;
		color: #5BA7FF;
		border-bottom: 4rpx solid #5BA7FF;
	}

	.row_content {
		height: 240rpx;
		border: 2rpx solid #c4c4c49c;
		background: white;
		margin: 20rpx;
		padding: 10rpx 20rpx;
		border-radius: 10rpx;
		position: relative;
		display: flex;
		justify-content: flex-start;
		align-items: center;
	}

	.big_img {
		width: 140rpx;
		height: 140rpx;
	}

	.detail {
		margin-left: 10px;
	}

	.course_name {
		font-weight: bold;
	}

	.time {
		font-size: 26rpx;
		color: #999999;
		margin: 10rpx 0rpx;
	}

	.lower_right {
		position: absolute;
		right: 20rpx;
		bottom: 10rpx;
	}

	.line {
		border-right: 2rpx solid #555555;
		padding-right: 14rpx;
	}

	.small-box {
		margin-left: 10rpx;
	}

	.small-box text {
		font-size: 24rpx;
		color: #409eff;
	}

	.small_img {
		width: 30rpx;
		height: 30rpx;
	}
</style>

主要样式:

 

  • 1
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
UniApp中自定义顶部滑动导航的步骤如下: 1. 首先,在`page.json`文件中定义自定义导航栏的样式。你可以设置`navigationStyle`为`custom`来启用自定义导航栏样式。例如: ``` { "path": "pages/charts/charts", "style": { "navigationBarTitleText": "", "enablePullDownRefresh": false, "navigationStyle": "custom" } } ``` 2. 接下来,在页面对应的`style`部分中定义导航栏样式和滑动内容区的样式。例如: ``` <style lang="scss"> // 顶部导航栏 .chartsTop { width: 750rpx; position: fixed; top: 0; z-index: 999; background-color: blue; } // 导航栏里边文字 .text { position: absolute; left: 20rpx; bottom: 10rpx; color: #ffffff; } // 内容顶部背景 .top { height: 300rpx; width: 100%; background-color: blue; position: fixed; z-index: -1; display: flex; justify-content: center; .top-img { width: 240px; height: 180px; } } // scroll-view 里边内容滑动 包裹chartsContent 透明 .test { position: fixed; background-color: rgba(0, 0, 0, 0); height: 1400rpx; border: 0; box-sizing: border-box; } // 可滑动view .chartsContent { width: 100%; height: 1400rpx; position: absolute; margin-top: 290rpx; border: 0; box-sizing: border-box; border-radius: 20rpx; background-color: #fff; } </style> ``` 3. 最后,在自定义页面的模板中,使用对应的类名来应用定义的样式。例如: ``` <view class="container"> <!-- 导航栏 --> <view class="chartsTop" :style="{ height: contentTop }"> <text class="text" :style="{ fontSize: contentFontSize }">排行</text> </view> <!-- 顶部背景 --> <view class="top" :style="{ top: contentTop }"> <img class="top-img" src="/static/images/othericons/正在开发中.png" alt="" /> </view> <scroll-view scroll-y="true" class="test" :style="{ top: contentTop }"> <!-- 可滑动view --> <view class="chartsContent"> <!-- 内容 --> </view> </scroll-view> </view> ``` 通过以上步骤,你可以在UniApp中自定义顶部滑动导航。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* *3* [uniapp小程序自定义导航栏,可滑动view](https://blog.csdn.net/qq_44184452/article/details/131044118)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"] [ .reference_list ]

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值