uniapp自定义导航栏以及页面加背景

如果想给uniapp的页面加背景图片的话,疯狂度了之后会发现uniapp中背景图片用本地图片不起效果,所以一般用网络路径,之后又会发现,页面如果直接加背景的话有可能会遇到页面内容不够,背景撑不满整个页面,如果给页面根元素加 height: 100vh;的话页面上的东西就没法滚动了,所以最好是结合scroll-view一起做。

pages.json中:

javascript 复制代码
		{
			"path": "pages/hotelInfo/hotelInfo",
			"style": {
				"navigationStyle": "custom",	//自定义导航栏
				"enablePullDownRefresh": false,	//关闭页面下拉刷新
				"disableScroll": true			//不允许页面滑动
			}
		}

页面:

javascript 复制代码
<template>
	<view class="ye">
		<scroll-view scroll-y="true" class="scrollView" @scroll="scroll">
			<view class="fanhui" :class="{isNavbar : isNavbar}"
				:style="{paddingTop:paddingTop + 'px',height:height + 'px'}">
				<view class="content">
					<uni-icons :size="height * 0.8 + 'px'" color="#000000" type="back" @click="goBack()"></uni-icons>
					<view class="title">
						页面标题
					</view>
				</view>
			</view>
			<view class="contentC"></view>
		</scroll-view>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				height: 0,
				paddingTop: 0,
				isNavbar: false,

			};
		},
		onLoad(query) {
			//设置导航条参数
			let menuButtonInfo = uni.getMenuButtonBoundingClientRect();
			this.paddingTop = menuButtonInfo.top;
			this.height = menuButtonInfo.height;
		},
		methods: {
			goBack() {
				// uni.navigateBack()
				uni.reLaunch({
					url: "/pages/home/home"
				})
			},
			scroll(e){
				console.log(e)
				const scrollTop = e.detail.scrollTop;
				// 导航条颜色透明渐变
				if (scrollTop <= 50) {
					this.isNavbar = false
				} else {
					this.isNavbar = true
				}
			}
		}
	};
</script>

<style lang="scss">
	.ye {
		height: 100vh;

		@keyframes backgroundColorAnimation {
			0% {
				background-color: transparent;
			}

			100% {
				background-color: #fef2e9;
			}
		}

		.isNavbar {
			background-color: #fef2e9;
			animation: backgroundColorAnimation 0.5s;
		}

		.fanhui {
			z-index: 9;
			width: 100%;
			color: #100F0F;
			position: fixed;

			.content {
				width: 94%;
				height: 100%;
				margin: 0 auto;

				display: flex;
				align-items: center;

				.title {
					font-weight: 500;
					font-size: 32rpx;

					left: 50%;
					position: absolute;
					transform: translateX(-50%);
				}

			}
		}

		.scrollView {
			width: 100%;
			height: 100%;
			background-image: url("https://cdn.15803565366.com/uniapp/bg.png");
			background-repeat: no-repeat;
			background-size: cover;
		}
		
		.contentC{
			padding: 26rpx;
			box-sizing: border-box;
		}
	}
</style>
相关推荐
teeeeeeemo5 分钟前
Vue数据响应式原理解析
前端·javascript·vue.js·笔记·前端框架·vue
Sahas10199 分钟前
__VUE_PROD_HYDRATION_MISMATCH_DETAILS__ is not explicitly defined.
前端·javascript·vue.js
Jinxiansen021119 分钟前
Vue 3 实战:【加强版】公司通知推送(WebSocket + token 校验 + 心跳机制)
前端·javascript·vue.js·websocket·typescript
MrSkye20 分钟前
React入门:组件化思想?数据驱动?
前端·react.js·面试
BillKu29 分钟前
Java解析前端传来的Unix时间戳
java·前端·unix
@Mr_LiuYang29 分钟前
网页版便签应用开发:HTML5本地存储与拖拽交互实践
前端·交互·html5·html5便签应用
JacksonGao33 分钟前
一分钟带你了解React Fiber的工作单元结构!
前端·react.js
moxiaoran575333 分钟前
uni-app学习笔记二十四--showLoading和showModal的用法
笔记·学习·uni-app
前端农民晨曦34 分钟前
深入浏览器事件循环与任务队列架构
前端·javascript·面试
Vhen36 分钟前
Taro Echarts封装内外环形饼图
前端