+
95
-

微信小程序设置navigationStyle:custom后如何获得右侧胶囊位置?

微信小程序设置navigationStyle:custom后如何获得右侧胶囊位置?,自定义菜单的时候就可以保持与胶囊菜单位置一直了,请问怎么计算出来,有没有原生的api提供

网友回复

+
16
-

有接口可以实现

1、首先在要自定义的页面中的pageName.json中加上,"navigationStyle": "custom" 隐藏微信小程序原生导航栏。 2、调用微信api获取手机系统屏幕高度和导航栏高度

getTopHeight:function(){
    //获取胶囊位置信息
    let menuButtonObject = wx.getMenuButtonBoundingClientRect();
    //定义导航位置参数
    var globalData={
      navHeight:0,
      navTop:0,
      windowHeight:0,
      ww:0,
      hh:0,
    }
    var navTop;
    var navHeight;
    //获取手机系统信息
    wx.getSystemInfo({
      success: res => {
        //导航高度
        var statusBarHeight = res.statusBarHeight;
        navTop = menuButtonObject.top;
        navHeight = statusBarHeight + menuButtonObject.height + (menuButtonObject.top - statusBarHeight) * 2;
        globalData.navHeight = navHeight;
        globalData.navTop = navTop;
        globalData.windowHeight = res.windowHeight;
        //可视窗口宽度
   ...

点击查看剩余70%

我知道答案,我要回答