小程序setNavigationBarColor设置背景渐变,图片渐变

小程序setNavigationBarColor设置背景渐变

第一种:渐变图片

html 复制代码
<view class="Box" :style="'height:'+s_topImg+'rpx'" >
			<!-- 设置背景图片及自适应高度 -->
			<view class="contain-box" :style="[{backgroundImage:'url('+backgroundImg+')'}, 'height:'+s_topImg+'rpx']" >
				<!-- 滚动动态设置样式 -->
				<view :class="scrollTopShow?'top-item1':'top-item2'":style="'background:rgba(48, 154, 236,' +topOpacity+')'">
					<!-- 胶囊以上占位盒子 -->
					<view :style="'height:'+s_top+'rpx', 'line-height:'+s_top+'rpx'"></view>
					<!-- 动态设置高和行高与胶囊保持一致 -->
					<view class="title-type" :style="['height:'+s_height+'rpx','line-height:'+s_height+'rpx']">
						项目订阅管理
					</view>
				</view>
			</view>
		</view>

<script>
	export default {
		data() {
			return {
				backgroundImg: '/subscribe/static/img/topbg1.jpg', // 顶部背景图
				s_top: '100', //胶囊距离顶部距离
				s_height: '100', //胶囊行高	
				s_topImg: '80',
				scrollTopShow: true, // 顶部颜色默认隐藏
				topOpacity: 0,
			}
		},
		created() {
			this.initTopImg();
		},
		// 监听滚动事件
		onPageScroll(e) { //nvue暂不支持滚动监听,可用bindingx代替
			let scrollTop = e.scrollTop;
			this.topOpacity = scrollTop / 300 > 0.9 ? 1 : scrollTop / 300
			if (e.scrollTop != 0) {
				this.scrollTopShow = false;
			} else {
				this.scrollTopShow = true;
			}
		},
		methods: {
			// 初始化顶部背景图
			initTopImg() {
				let menuButtonInfo = uni.getMenuButtonBoundingClientRect();
				this.s_top = menuButtonInfo.top * 2;
				this.s_topImg = menuButtonInfo.top * 2+100 ;//+ 508
				this.s_height = menuButtonInfo.height * 2;
			},
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #f8f9fa;
	}
	.Box{
		position: sticky;
		    top: 0;
		    z-index: 100;
	}
	.contain-box {
			width: 100%;
			background-size: 100% 100%;
			align-items: center;
	
			.top-item1 {
				.title-type {
					font-size: 36rpx;
					font-weight: 400;
					color: #fff;
					display: flex;
					justify-content: center;
					/* 水平居中 */
				}
			}
	
			.top-item2 {
				position: fixed;
				top: 0;
				width: 100%;
	
				.title-type {
					font-size: 36rpx;
					font-weight: 400;
					color: #fff;
					display: flex;
					justify-content: center;
					/* 水平居中 */
				}
			}
		}
	.top{
	   width: 100%;
	   height: 200px;
	   background: linear-gradient(121deg, #94C7FE -1%, #1890FF 102%);
	   box-shadow: 24px 52px 100px 0px rgba(90, 108, 234, 10%)
	}

	.setting{
		.header {
			background: linear-gradient(135deg, #007aff 0%, #0056d6 100%);
			color: white;
			padding: 20px 16px;
			text-align: center;
			// position: sticky;
			// top: 0;
			z-index: 100;
			box-shadow: 0 2px 10px rgba(0, 122, 255, 0.2);
		}
		
		.header h1 {
			font-size: 1.25rem;
			font-weight: 600;
			margin-bottom: 4px;
		}
		
		.header p {
			font-size: 0.875rem;
			opacity: 0.9;
		}
		
		.main {
			padding: 16px;
			padding-bottom: 100px;
		}
		
		.list {
			background: white;
			border-radius: 12px;
			margin-bottom: 16px;
			padding: 16px;
			box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
			transition: all 0.3s ease;
		}
		
		.list:active {
			transform: scale(0.99);
		}
		
		.first {
			display: flex;
			justify-content: space-between;
			align-items: center;
			margin-bottom: 12px;
		}
		
		.title {
			font-size: 1.125rem;
			font-weight: 600;
			color: #2c3e50;
		}
		
		.subtitle {
			font-size: 0.75rem;
			padding: 4px 10px;
			border-radius: 10px;
			font-weight: 500;
		}
		
		/* 分类标识颜色 - 使用主题色变体 */
		.color1 {
			background-color: rgba(0, 122, 255, 0.1);
			color: #007aff;
		}
		
		.color2 {
			background-color: rgba(0, 122, 255, 0.15);
			color: #0062cc;
		}
		
		.color3 {
			background-color: rgba(0, 122, 255, 0.2);
			color: #0052b3;
		}
		
		.content {
			margin: 12px 0;
			padding: 12px;
			background: #f9f9f9;
			border-radius: 8px;
		}
		
		.second {
			display: flex;
			flex-direction: column;
		}
		
		.secondTip {
			font-weight: 600;
			color: #2c3e50;
			margin-bottom: 8px;
			font-size: 0.875rem;
		}
		
		.secondList {
			display: flex;
			flex-wrap: wrap;
			gap: 8px;
		}
	
	}

	
</style>

2. 渐变颜色

<view class="Box" :style="'height:'+s_topImg+'rpx'" @touchmove.prevent>

<uni-icons type="left" size="25" @click="goBack" class="iconback">
项目订阅管理

相关推荐
CHU7290352 小时前
直播商城APP前端功能全景解析:打造沉浸式互动购物新体验
java·前端·小程序
黑客老李12 小时前
web渗透实战 | js.map文件泄露导致的通杀漏洞
安全·web安全·小程序·黑客入门·渗透测试实战
游戏开发爱好者81 天前
日常开发与测试的 App 测试方法、查看设备状态、实时日志、应用数据
android·ios·小程序·https·uni-app·iphone·webview
2501_915106321 天前
app 上架过程,安装包准备、证书与描述文件管理、安装测试、上传
android·ios·小程序·https·uni-app·iphone·webview
2501_915106321 天前
使用 Sniffmaster TCP 抓包和 Wireshark 网络分析
网络协议·tcp/ip·ios·小程序·uni-app·wireshark·iphone
宠友信息1 天前
2025社交+IM及时通讯社区APP仿小红书小程序
java·spring boot·小程序·uni-app·web app
光影少年2 天前
AIGC + Taro / 小程序
小程序·aigc·taro
2501_915918412 天前
在 iOS 环境下查看 App 详细信息与文件目录
android·ios·小程序·https·uni-app·iphone·webview
2501_916007472 天前
没有 Mac 用户如何上架 App Store,IPA生成、证书与描述文件管理、跨平台上传
android·macos·ios·小程序·uni-app·iphone·webview
天空属于哈夫克32 天前
Go 语言实战:构建一个企微外部群“技术贴收藏夹”小程序后端
小程序·golang·企业微信