你还在发愁小程序自定义导航栏吗?
先说一下我的需求吧,因为我们的小程序是嵌套了webview。 点击webview里面的项目,点的层级太深,用户后退很麻烦。然后pm又找了一个自定义的导航的小程序,发现别人可以,然后我就开始研究。 小程序自定义导航栏开发注意点与参考文档
非自定义导航栏高度怎么计算?
—— 不完全统计(ip6,ip5,ip6p,ipx,小米mix2,小米5等综合了开发工具提供的数据和真机数据)所得 配置"window": {
"navigationBarBackgroundColor": "#fff","navigationBarTextStyle": "black",0);">"backgroundColor": "navigationStyle": "custom"
},复制代码
这里navigationStyle 配置修改之后就只剩一个胶囊按钮,也就意味着所有页面的导航都的自定义实现,你可以选择模版或者组件来开发,这里我是选择用的组件开发。 然后定义导航的各个数值,我是在app。js 里面定义的 title_height: "64",statusbarHeight: "24",51); font-weight: 700;">titleIcon_height: "32",51); font-weight: 700;">titleIcon_width: "87",51); font-weight: 700;">title_top: title_text: "xxx",// iphone X + 24
prefix: 24
复制代码
组件wxml的代码 <view>
<view class="title" style="height:{{title_height}}px;padding-top:{{statusbarHeight}}px;background-color:{{isIndex?'#175dc6':'#fff'}}">
<"title_text" style="color:{{isIndex?'#fff':'#000'}}">{{title_text}}</view>
<view wx:if="{{isShow}}" class="title_icon" style="top:{{title_top}}px;height:{{titleIcon_height}}px;width:{{titleIcon_width}}">
<image bindtap="_goBack" class="floatL" src="/img/fanhui_icon.png"></image>
<"floatL"></view>
<"_goHome" src="/img/home_icon.png"></image>
</view>
</view style='height:}px;'></view>
</view>复制代码
wxss的代码 .title { width: 100%; background-color: #175dc6; box-sizing: border-box; position: fixed; transform: translateZ(0); z-index: 999990;}
.title_text { text-align: center; font-size: 37rpx; color: #fff; line-height: 44px;}
.title_icon { top: 54rpx; left: 16rpx; border-radius: 64rpx; border: 0.5px solid #ebe48e; display: flex;}
.title_icon image { height: 20px; padding-top: 5px; display: inline-block; overflow: hidden;}
view { 18px; border-left: 1px solid #bfb973; margin-top: 6px;}
.floatL { float: left;}
image:nth-of-type(1),:nth-of-type(2) { padding-right: 10px; padding-bottom: padding-left: 10px;}复制代码
js的代码 const app = getApp();
Component({
properties: {
isShow: { // 是否显示后退按钮
type: String, value: "1"
}, isIndex: { // 是否主页
type: Boolean, value: false,}, title_height: { //
type: String, value: app.config.title_height, titleIcon_height: {
type: String, value: app.config.titleIcon_height, titleIcon_width: {
type: String, value: app.config.titleIcon_width, statusbarHeight: {
type: String, value: app.config.statusbarHeight, title_top: {
type: String, value: app.config.title_top, title_text: {
type: String, value: app.config.title_text, methods: {
_goBack: function() {
wx.navigateBack({
delta: 1
});
}, _goHome: function() {
wx.switchTab({
url: "/pages/index/index"
});
}
}
})复制代码
这样组件就写好了? 只需要在你每个页面里面用这个组件传不同的值就可以了。 应用<header isIndex="true" title_text="首页" isShow=""></header> 在首页的wxml应用。
json 文件里面的配置
"navigationBarTitleText": "啦啦啦",0);">"#175dc6",0);">"usingComponents": {
"header": "/components/layout/header/header"
}复制代码
效果如图适配上可能会有点问题,希望大神有更好的解决方案,告诉我哟。 一步步记录自己的踩坑历程~我要做到我技术不是最好的,但我给你总结的小程序的东西是最简单粗暴的哈哈哈 我的博客:tada: 送我一朵小发发~ 这个代码的排版我服了,懒得高了,我会发到博客上让大家看的。 作者:?Jiyr 来源:https://juejin.im/post/5b7d5f5551882542e32a99c6 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |