当前位置: 首页 > article >正文

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

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

pages.json中:

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

页面:

<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>

http://www.kler.cn/news/307142.html

相关文章:

  • CSP-J算法基础 计数排序
  • mis_table.cs 与 csharp_mis_table.h
  • Oracle(121)如何进行数据文件的恢复?
  • Linux中使用Docker构建Nginx容器完整教程
  • k8s使用本地docker私服启动自制的flink集群
  • OKHttp实现原理分享
  • vue3 指定元素全屏 screenfull(可直接粘贴使用)
  • 《凡人歌》:网络安全组电话响3声必须接,安全组长被压迫患得惊恐症、抑郁症
  • HTTP跨域请求时为什么要发送options请求
  • 【LLMs对抗性提示:提示泄漏、非法行为、DAN、Waluigi效应、 游戏模拟器、防御策略————】
  • JSON教程
  • 聪明办法学 Python 第二版.1.学习安排
  • vue3项目实现全局国际化
  • 深入理解C++中的std::string::substr成员函数:子串操作的艺术
  • 增强LinkedList实现瑞士轮赛制编排
  • C++课程笔记 类和对象
  • Android JobScheduler介绍
  • 介绍一些免费 的 html 5模版网站 和配色 网站
  • Spring的核心思想
  • Linux常用命令以及操作技巧
  • 数据库之索引<保姆级文章>
  • 纯血鸿蒙NEXT常用的几个官方网站
  • 你天天用微服务还不知道心跳检测机制是什么?
  • Redis的配置与优化
  • spring模块(六)spring event事件(3)广播与异步问题
  • 鸿蒙OS 资源文件
  • 七、结合Landsat、夜光数据建成区提取——K均值聚类和监督分类提取精确的建成区边界
  • AI为云游戏带来的革新及解决方案:深度技术剖析与未来展望
  • windows下自启springboot项目(jar+nginx)
  • 安卓网址自动添加%,显示网页异常