Skip to content

sud.getMenuButtonBoundingClientRect ​

同步获取右上角菜单按钮的布局位置,用于布局时避让菜单按钮。

javascript
const rect = sud.getMenuButtonBoundingClientRect();

参数 ​

无。

返回值 ​

Object | null。无法获取菜单按钮位置时返回 null,使用前请判空。

坐标以屏幕左上角为原点,以下数值单位均为 px。

属性类型说明
widthnumber菜单按钮宽度
heightnumber菜单按钮高度
topnumber上边界坐标
rightnumber右边界坐标
bottomnumber下边界坐标
leftnumber左边界坐标

使用说明 ​

使用前请确认目标 App 提供菜单按钮位置信息。此接口同步返回结果,不使用回调或 Promise。游戏使用其他坐标系布局时,应先将返回坐标转换到相同坐标系。

示例 ​

javascript
const rect = sud.getMenuButtonBoundingClientRect();

if (rect) {
  console.log('菜单按钮位置', rect.left, rect.top, rect.width, rect.height);
} else {
  console.log('当前无法获取菜单按钮位置');
}