微信小程序吸顶导航栏 + 状态栏高度自适应(自定义顶栏)
精准获取胶囊按钮与状态栏高度,完美适配所有刘海屏/灵动岛机型。
精准获取胶囊按钮与状态栏高度,完美适配所有刘海屏/灵动岛机型。
<view style="padding-top: {{statusBarHeight}}px; height: {{navBarHeight}}px; position: sticky; top: 0; background: #fff; display: flex; align-items: center; padding-left: 24rpx;">
<text style="font-weight: 700;">自定义吸顶标题</text>
</view>Page({
data: { statusBarHeight: 20, navBarHeight: 44 },
onLoad() {
const { statusBarHeight } = wx.getWindowInfo();
const menu = wx.getMenuButtonBoundingClientRect();
const navBarHeight = (menu.top - statusBarHeight) * 2 + menu.height;
this.setData({ statusBarHeight, navBarHeight });
},
});