当前位置:网站首页>Wechat applet - screen height
Wechat applet - screen height
2022-07-29 05:39:00 【Program ape runs forward】
screenheight Represents the height of the mobile screen ( Including the top status bar and webview Render area and tabbar And navigation bar )
windowHeight representative webview Area , It does not include the status bar, navigation bar and tabbar,
If set pages.json in navigationStyle Value custom, that windowHeight representative webview Add the status bar and the navigation bar , barring tabbar
SelectorQuery.select ( Select node | The first match in the page )
wx.createSelectorQuery().in(that).select(el).boundingClientRect().exec(res => {
page({
onLoad () {
this.queryFixedElementInfo();
},
// Query the height of the ceiling element
queryFixedElementInfo () {
// Get one 'SelectorQuery' example
const query = wx.createSelectorQuery();
// choice id by 'fixed-content' Page elements of , Query its layout location
query.select('#fixed-content').boundingClientRect();
// empty-element Select a node that does not exist on the page , Also initiate a query , I just want to remind you to look at the code snippet , For uncertain data , Try to give a default value when taking values , Or judge the data type and then carry out the corresponding operation , In order to avoid incorrect operation , Affect the subsequent logic
// The actual application scenario may be , Use wx:if Elements of control , Not rendered at query
query.select('#empty-element').boundingClientRect();
// Official annotation : ' Execute all requests *** The result of the request forms an array in the order of the request *** stay callback In the first parameter of .'
query.exec(res => {
const [ fixedElement, emptyElement ] = res;
// The first item is the query page node '#fixed-content' The return value of ,
const {
bottom, dataset, height, left, right, top, width } = fixedElement || {
};
// Query the width and height of the element itself in the object
console.log(`%c Query the width and height of the element :${
width} * ${
height}`, 'color: #282C34');
/** * top Is the distance from the top , bottom Is the distance from the bottom of the element to the top * You can adjust the position of elements in the interface by yourself * bottom - top === height; * console.log(bottom - top === height); // true */
console.log(`%c Query the boundary coordinates of the element relative to the view \n On :${
top}\n Next :${
bottom}\n Left :${
left}\n Right :${
right}`, 'color: #a52222');
// Query the custom attributes carried in the element
console.dir(dataset);
// Because the second item does not exist in the page , So there is no return value , Remember to give a default value when taking values from inside
const {
id } = emptyElement || {
};
console.log(`%c The value obtained by deconstruction is :${
id}, But there is no error , If necessary, you can assign a default value when deconstructing `, 'color: red');
/** The following wording will report an error , Affect the subsequent business logic */
// console.log(res[1].id || emptyElement.id);
// do sth...
// Record '#fixed-content' Distance from the top
this.setData({
fixedTop: top });
});
},
// Page slide event
onPageScroll (e) {
const {
scrollTop } = e;
const {
fixedTop, isFixed } = this.data;
if (scrollTop >= fixedTop && !isFixed) {
this.setData({
isFixed: true });
return;
}
if (scrollTop < fixedTop && isFixed) {
this.setData({
isFixed: false });
return;
}
},
}

1. Different scopes :screenHeight Is the height of the integrated mobile screen ,windowHeight yes webview( Mobile notification bar is not included 、 Applet title bar and tabBar) Height ;

The picture above shows us from systemInfo The actual performance of the obtained data , Apple X Take Liu Haiping as an example ( The principle of all Android bangs is similar ): The outermost red box is the screen size , The blue box is the security area, which literally means the page area that developers can manipulate , The yellow box above is the status bar of the mobile phone , The green area is what we want to customize navigationBar.
so , Navigation bar safeArea The upper part of , If you use the native navigation bar , Below the navigation bar is the real controllable range .
In fact, our custom navigation bar is also in this safeArea The inner is most harmonious with the capsule . The key reason is that wechat takes the capsule button in the upper right corner as a built-in component , Only black and white , That is, we can't change its size, position, transparency, etc , So in order to match the capsule button , The general customized navigation bar position is also consistent with the position in the figure above .
The following is an example , The red box above is statusBar, The height is known ; The red box below is the text , Sandwiched in the middle is one of the solutions navigationBarHeight; The yellow is the original capsule button, which is also in the vertical center , The height of the capsule button is known based on the coordinate information in the upper left corner , It's not hard to get out ,navigationBarHeight = Blue frame height × 2 + Capsule button .height.( Blue frame height = Capsule button .top - statusBarHeight)
Function directly return Promise,await Get yes Object
wx.createSelectorQuery().in(this)
query
.select(‘.ec-canvas’)
.fields({ node: true, size: true })
.exec(res => {
边栏推荐
- Clickhouse learning (XI) clickhouseapi operation
- 第一周总结
- Using POI TL to insert multiple pictures and the same data of multiple rows of cells into the table cells of word template at one time, it is a functional component for automatic merging
- Occt learning 002 - environment construction
- Global components component registration
- Application of Huffman tree and Huffman coding in file compression
- 使用微信小程序扫码登录系统PC端web的功能
- Three handshakes and four waves for the interview summary
- 字符类型转换
- Day 1
猜你喜欢

Qtcreator+cmake compiler settings

实现简单的数据库查询(不完整)
![Niuke network programming problem - [wy22 Fibonacci series] and [replace spaces] detailed explanation](/img/39/1d4fb1774b0f9f7c9bb13221f0d6c2.png)
Niuke network programming problem - [wy22 Fibonacci series] and [replace spaces] detailed explanation

ClickHouse学习(六)语法优化

【TypeScript】TypeScript中类型缩小(含类型保护)与类型谓词

Clickhouse learning (VI) grammar optimization

无重复字符的最长字串

微信小程序-组件传参,状态管理
![[C language series] - realize the exchange of two numbers without creating the third variable](/img/7c/468000bcbf740c9dd3535f2734728a.png)
[C language series] - realize the exchange of two numbers without creating the third variable

Three handshakes and four waves for the interview summary
随机推荐
Wechat applet video upload component is directly uploaded to Alibaba cloud OSS
Cmu15-213 shell lab experiment record
shell基本操作(上)
uniapp组件之选择选项(如套餐选择)
浅谈范式
个人学习笔记
【TypeScript】TypeScript中类型缩小(含类型保护)与类型谓词
重绘与回流的关系
js深拷贝-笔记
One dimensional array exercise
uniapp之常用提示弹框
link与@import导入外部样式的区别
TXT 纯文本操作
相对定位和绝对定位
ClickHouse学习(九)clickhouse整合mysql
Global components component registration
[C language series] - three methods to simulate the implementation of strlen library functions
Storage category
Solution: find the position of the first and last element in a sorted array (personal notes)
[C language series] - storage of deep anatomical data in memory (II) - floating point type