微信小程序顶部自定义基本上适配所以手机

1.先去设置顶部导航可以自定义
2.在app.js里面:
wx.getSystemInfo({
success: (e) => {
this.globalData.statusBar = e.statusBarHeight; //状态栏高度
let custom = wx.getMenuButtonBoundingClientRect(); //菜单按钮
this.globalData.custom = custom;
this.globalData.customBar = custom.bottom + custom.top - e.statusBarHeight;
}
})

3.新建一个构造器
wxml里面:

<view class="nav-back" style='top:{{statusBar}}px;' wx:if="{{icontext==1}}">
	<van-icon name="arrow-left" color="#5E4C4C" size="36rpx" bindtap="backpage" />
</view>
<view class='nav-title' style='top:{{statusBar}}px;' wx:if="{{navbartext !=''}}">{{navbartext}}</view>
js: const app = getApp() Component({ properties: { navbartext: { //由父页面传递的数据,变量名字自命名 type: String, value: "" }, icontext: { type: String, value: "" }, idno:{ type: String, value: "" } }, data: { statusBar: app.globalData.statusBar, customBar: app.globalData.customBar, custom: app.globalData.custom, height: '', }, attached: function() { // 获取是否是通过分享进入的小程序 this.setData({ share: app.globalData.share }) // 定义导航栏的高度 方便对齐 this.setData({ height: app.globalData.height }) }, methods: { backpage(){ wx.navigateBack({ complete: (res) => {
			},
		})
	}

}

})
css:
/* 顶部要固定定位 标题要居中 自定义按钮和标题要和右边微信原生的胶囊上下对齐 */
.nav-wrap {
position: fixed;
width: 100%;
top: 0;
left: 0;
background: #fff;
color: #000;
z-index: 9999999;

}

/* 标题要居中 */
.nav-title {
position: absolute;
text-align: center;
width: calc(100% - 340rpx);
left: 0;
right: 0;
bottom: 0;
top: 0;
margin: auto;
height: 60rpx;
font-size: 36rpx;
line-height: 60rpx;
pointer-events: none;
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
}

.nav-back {
position: absolute;
left: 0;
right: 0;
bottom: 0;
top: 0;
margin: auto;
height: 60rpx;
font-size: 36rpx;
line-height: 60rpx;
pointer-events: none;
text-overflow: ellipsis;
white-space: nowrap;
overflow: hidden;
left: 10px;
display: flex;
align-items: center;
}
.border{
border-bottom: 1px solid #CCCCCC;
}

然后再自己的页面引入
js里面 height: app.globalData.customBar,
把height设置在自己的页面中来站位置,避免导航下面的内容被挡住或者其他方法都行

苹果5苹果xs

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值