uniapp 官网解析地址
异步获取系统信息
参数名 | 类型 | 必填 | 说明 |
---|---|---|---|
success | Function | 是 | 接口调用成功的回调 |
fail | Function | 否 | 接口调用失败的回调函数 |
complete | Function | 否 | 接口调用结束的回调函数(调用成功、失败都会执行) |
success返回其他的参数(详细所有内容看官网)
注意:
uni.getSystemInfo({success: function(res) {// *****高度宽度的单位都是px console.log(res.screenHeight); // 屏幕高度,包含导航栏console.log(res.windowHeight); // 能够使用的窗口高度,不包含导航栏console.log(res.screenWidth); // 屏幕宽度console.log(res.windowWidth); // 能够使用的窗口宽度console.log("windowHeight:",res.windowHeight) let windowHeight = res.windowHeight;}
})
获取系统信息的同步接口。调用参数和返回值同上getSystemInfo。
uni.getSystemInfoSync({success: function(res) {// *****高度宽度的单位都是px console.log(res.screenHeight); // 屏幕高度,包含导航栏console.log(res.windowHeight); // 能够使用的窗口高度,不包含导航栏console.log(res.screenWidth); // 屏幕宽度console.log(res.windowWidth); // 能够使用的窗口宽度console.log("windowHeight:",res.windowHeight) let windowHeight = res.windowHeight;}
})
/*** 获取活动区域高度* @param { nodeName } 节点名字* @param { nodeHeight } 节点高度* @param { nodeMPHeight } 节点margin 和 padding 的高度* */
function getHeight(nodeName, nodeHeight = 0,nodeMPHeight = 0) {let pageHeight = uni.getSystemInfoSync().windowHeight; // 获取当前页面的高度console.log("pageHeight: ",pageHeight)// 获取结节高度方法// #ifdef H5const query = uni.createSelectorQuery();// #endif// #ifdef APPconst query = uni.createSelectorQuery().in(this)// #endif// 获取当前结节高度值let nHeight = nodeHeightquery.select(nodeName).boundingClientRect(data => {console.log("data.height: ",data.height)nHeight = data.height}).exec();let nowHeight = pageHeight - nHeight - nodeMPHeightconsole.log("nowHeight",nowHeight)return nowHeight + 'px'
}2. 调用
/*** 获取滚动高度--高度相关信息,要放在 onReady 里获取,太早取不到;* 单位都是px* 将rpx单位值转换成px* uni.upx2px(600) + 'px';* */
this.h = this.getHeight('#content-head', 0, uni.upx2px(20));