微信小程序置顶导航,替代原生导航栏

效果图:

思路:Navigation是小程序的顶部导航组件,当页面配置navigationStyle设置为custom的时候可以使用此组件替代原生导航栏,wx.getSystemInfoSync获取可使用窗口高度

wxml代码:

复制代码
<!-- 头部 -->
<view class="header" style="padding-top:{{statusBarHeight}}px">
<view class="searchbtn">
<image src="/pages/asset/img/search_03.jpg" class="search_pic"></image>
<view class="search_word"> 哪吒之魔童降世</view>
</view>
<view class="history"><image src="/pages/asset/img/time_05.jpg"></image></view>
</view>
<!-- 头部 -->

wxss代码:

复制代码
.header{ width: 100%; height: 58rpx; position: fixed; left: 0rpx; top: 0%; background: #fff; z-index: 111}
.searchbtn{ width: 50%; height: 58rpx; margin-top:2%; float: left;  margin-left:30rpx; border-radius: 45rpx; background: #f5f5f5;}
.search_pic{ display: block; width: 34rpx; height: 34rpx; float: left;margin-top: 3%; margin-left: 18%; }
.search_word{ font-size: 24rpx; float: left; color: #bbbbbb;font-family: '微软雅黑'; line-height: 58rpx; text-align: left; margin-left: 8rpx;}
.history{ display: block; width: 34rpx; height: 34rpx; float: left; margin-top:3.5%; margin-left:30rpx;}
.history image{ width: 34rpx; height: 34rpx;}

app.json修改window下navigationStyle 为 custom

复制代码
"window": {
"backgroundTextStyle": "light",
"navigationBarBackgroundColor": "#fff",
"navigationBarTitleText": "影视",
"navigationBarTextStyle": "black",
"navigationStyle": "custom"
},

最后, wx.getSystemInfoSync获取可使用窗口高度,app.js下,加上以下代码

复制代码
//app.js
App({
globalData: {
statusBarHeight: wx.getSystemInfoSync()['statusBarHeight']
},

页面js文件添加到data:

复制代码
Page({
data: {
statusBarHeight: app.globalData.statusBarHeight,
  }
})

微信小程序置顶导航,替代原生导航栏-遇见你与你分享

相关推荐
社会渣渣9 小时前
开发者工具正常、真机白屏:一次渲染差异排查
微信小程序
daguanren12 小时前
一个页面外壳,多页复用:weapp-vite / Wevu 布局的编译与动态切换
微信小程序
源码手记12 小时前
基于微信小程序的上门代厨厨师预约系统-毕设源码
微信小程序·小程序·课程设计
微订校园外卖系统12 小时前
自建自营小程序落地前,先把订单状态机与试单链路跑通
小程序·外卖系统·本地生活·微订
千寻技术帮13 小时前
基于微信小程序的点餐管理系统_50044(源码+脚本+文档)
mysql·微信小程序·小程序·毕业设计·springboot·点餐管理系统
AI源码13 小时前
中医药文化介绍小程序
小程序·notepad++
千寻技术帮1 天前
基于微信小程序的零食销售系统(源码+文档+脚本)50047
数据库·mysql·微信小程序·小程序·毕业设计·springboot·课程设计
源码手记2 天前
基于微信小程序的驾考刷题学习系统-毕设源码
学习·微信小程序·课程设计
lyz2468592 天前
uniapp-x在小程序使用uchart图表加载问题
小程序·uni-app
AI源码2 天前
心理健康教育小程序
小程序