uniapp自定义头部下滑渐变案例 复制可用

uniapp自定义头部下滑渐变案例 复制可用用

uniapp 模板

<template>
	<view class="box">
		<view class="nav_bar" >	
			<view class="status_bar"><!-- 这里是状态栏 --></view>
			<view class="status_box">
				<!-- 这里是返回上一页 图片为监听 -->
				<image class="status_back" src="/static/ico_left.png" mode="widthFix" @click="backshouw"></image>
				<!-- 这里是标题 -->
				<view class=" status_title">
					<text class="status_title_txt">这里是标题</text>
					<image class="status_title_img" src="/static/icon/zdy_ss.png" mode="widthFix" @click="searchshow">
						<!-- 这里是搜索图标,点击切换为搜索栏 -->
					</image>
				</view>
			</view>	
		</view>
		<view class="nav_bar_1":style="bgcolor"><!-- 默认显示背景--></view>   
		<view class="nav_bar_2" :style="bgcolor_1"><!-- 渐变显示背景--></view>
		<view class="place_holder"><!-- 占位符--></view>
		<view class="list">
			<view class="list_view">内容</view>
			<view class="list_view">内容</view>
			<view class="list_view">内容</view>
			<view class="list_view">内容</view>
			<view class="list_view">内容</view>
			<view class="list_view">内容</view>
			<view class="list_view">内容</view>
			<view class="list_view">内容</view>
		</view>
	</view>
</template>

uniapp css

.box{ width: 750rpx ; display: block;}
	.nav_bar {
		width: 750rpx;
		display: block;
		position: fixed;
		top: 0;
		z-index: 999;
		
		
	}
	.nav_bar_1 {
		width: 750rpx;
		display: block;
		position: fixed;
		top: 0;
		z-index: 998;
		background: #00a0e9;
		height: calc(var(--status-bar-height) + 44px);
		
	}
	
	.nav_bar_2{width: 750rpx;
		display: block;
		position: fixed;
		top: 0;
		z-index: 997;
		background: #f00;
		opacity: 0;
		height: calc(var(--status-bar-height) + 44px);
		
		}

	.place_holder {
		width: 750rpx;
		display: block;
		height: calc(var(--status-bar-height) + 44px);
	}

	/*状态栏*/
	.status_bar {
		height: var(--status-bar-height);
		width: 750rpx;
		display: block;
		
	}
	

	/*导航栏*/
	.status_box {
		width: 750rpx;
		height: 44px;
		
		display: flex;
		justify-content: flex-start;
		align-items: center;
		
	}

	.status_back {
		width: 50rpx;
		height: 50rpx;
		display: block;
		margin-left: 15rpx;
	}

	/*显示标题*/
	.status_title {
		width: 655rpx;
		height: 70rpx;
		display: flex;
		justify-content: flex-start;
		align-items: center;
		margin-left: 15rpx
	}

	.status_title_txt {
		width: 590rpx;
		height: 70rpx;
		line-height: 70rpx;
		display: block;
		margin-right: 15rpx;
		color: #fff;
		text-align: center;
	}

	.status_title_img {
		width: 50rpx;
		height: 50rpx;
		display: block;
		margin: auto;
	}

	.list{ width: 750rpx; display: block;}
	.list_view{ width: 720rpx; display: block; height: 500rpx;  line-height: 500rpx;
	 font-size: 60rpx; text-align: center; color: #fff;
	margin: auto; margin-top: 10rpx; border-radius: 10rpx; background-color: #00a0e9; }

uniapp javascript

export default {
		data() {
			return {
				bgcolor: ''
				
			};
		},
		methods: {

			// 通过这个方法,监听滑动的距离,通过距离,动态修改透明的
			onPageScroll(e) {
				if (e.scrollTop >= 0 && e.scrollTop <= 8) {
					this.bgcolor = "opacity:1"
					this.bgcolor_1 = "opacity:0"
				} else if (e.scrollTop > 8 && e.scrollTop <= 16) {

					this.bgcolor = "opacity:0.9"
					this.bgcolor_1 = "opacity:0.1"
				} else if (e.scrollTop > 16 && e.scrollTop <= 24) {
					this.bgcolor = "opacity:0.8"
					this.bgcolor_1 = "opacity:0.2"
				} else if (e.scrollTop > 24 && e.scrollTop <= 32) {
					this.bgcolor = "opacity:0.7"
					this.bgcolor_1 = "opacity:0.3"
				} else if (e.scrollTop > 32 && e.scrollTop <= 40) {
					this.bgcolor = "opacity:0.6"
					this.bgcolor_1 = "opacity:0.4"
				} else if (e.scrollTop > 40 && e.scrollTop <= 48) {
					this.bgcolor = "opacity:0.5"
					this.bgcolor_1 = "opacity:0.5"
				} else if (e.scrollTop > 48 && e.scrollTop <= 56) {
					this.bgcolor = "opacity:0.4"
					this.bgcolor_1 = "opacity:0.6"
				} else if (e.scrollTop > 56 && e.scrollTop <= 64) {
					this.bgcolor = "opacity:0.3"
					this.bgcolor_1 = "opacity:0.7"
				} else if (e.scrollTop > 64 && e.scrollTop <= 72) {
					this.bgcolor = "opacity:0.2"
					this.bgcolor_1 = "opacity:0.8"
				} else if (e.scrollTop > 72 && e.scrollTop <= 80) {
					this.bgcolor = "opacity:0.1"
					this.bgcolor_1 = "opacity:0.9"
				} else if (e.scrollTop > 80) {
					this.bgcolor = "opacity:0"
					this.bgcolor_1 = "opacity:1"
				}
			}
		},
		
		onLoad() {

			this.bgcolor = "opacity:1"
		}
	};

uniapp 效果如下

自定义头部渐变

要在uniapp自定义tabbar的样式,可以按照以下步骤进行操作: 1. 打开项目根路径下的App.vue文件 2. 在文件中增加以下代码: ```html <style lang="scss"> uni-tabbar { .uni-tabbar { // 设置tab背景 background-image: linear-gradient(to top, #FAF8F8, #FFFFFF)!important; // 若需要使用背景图片,或者渐变色,背景色和背景图片最多选择一个进行设置 .uni-tabbar-border { // 设置tabBar上边框的颜色 background-color: #F7F4F4!important; } .uni-tabbar__bd { // 设置tabBar单项的样式 .uni-tabbar__icon { // 设置图标大小 width: 48upx!important; height: 48upx!important; } .uni-tabbar__label { // 设置文字大小 font-size: 20upx!important; } } } } </style> ``` 3. 保存文件后,即可自定义tabbar的样式。 这样,你就可以根据自己的需求,通过修改对应的样式来实现uniapp自定义tabbar的样式。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [uniapp自定义tabbar图标样式](https://download.csdn.net/download/weixin_45826772/86754568)[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: 33.333333333333336%"] - *2* [uniapp 修改tabBar图标大小和navigationBar字体大小(转载,仅作记录)](https://blog.csdn.net/Gabriel_wei/article/details/124919599)[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: 33.333333333333336%"] - *3* [uniapp自定义tabbar](https://blog.csdn.net/TYD0313/article/details/127340852)[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: 33.333333333333336%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

功能点分享

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值