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

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.lryc.cn/news/439243.html

相关文章:

  • MacOS Sonoma(14.x) 大写模式或中文输入法下的英文模式,光标下方永远会出现的CapsLock箭头Icon的去除办法
  • C#基础(10)变长参数和参数默认值
  • Vue转React开发经验分享——hooks写法如何触发react生命周期、如何触发数据更新?
  • 算法入门-贪心1
  • element-plus的面包屑组件el-breadcrumb
  • 推荐几个网盘资源站给大伙,找资源更方便
  • 【Qt】Qml界面中嵌入C++ Widget窗口
  • Python快速入门 —— 第五节:接口开发
  • 利用secureCRT向虚拟机发送文件(secureCRT安装使用教程)
  • AI杂七杂八系列(1)——工程篇
  • 学习大数据DAY58 增量抽取数据表
  • HTTPTomcat
  • Python数据分析-Matplotlib快速入门
  • 重塑在线软件开发新纪元:集成高效安全特性,深度解析与评估支持浏览器在线编程的系统架构设计
  • 【鸿蒙OH-v5.0源码分析之 Linux Kernel 部分】003 - vmlinux.lds 链接脚本文件源码分析
  • MongoDB实现高级RAG:Parent-Document检索技术详解
  • 胡学乱想----前端知识点(css色彩)
  • GEE 案例——利用MODIS数据和NDWI指数进行美国五大湖水体计算和时序分析(直方图统计和面积统计)
  • 【jvm】记一次hive堆heap内存溢出的排查
  • 编译运行 webAssembly(wasm)
  • Linux bash 关联数组
  • 选择排序
  • SQL数据库(MySQL)
  • 在MindSearch中使用SiliconCloud:全面指南**
  • C++(2)之Linux多线程服务端编程总结
  • 【AI视频】复刻抖音爆款AI数字人作品初体验
  • Mysql 面试题总结
  • stack - queue
  • 微软九月补丁星期二发现了 79 个漏洞
  • 研1日记12