uniapp gets page height and element height

1. Get page height

The system information can be obtained through the uni.getSystemInfoSync() method, including page height and other information.

const { windowHeight } = uni.getSystemInfoSync(); // 获取页面高度

Second, get the height of the element

For example, there is a King Kong area, we need to get the height of this area:

<view class="square_giant">
	<block v-for="item in giantList" :key="item.id">
		<view class="square_giant_item">
			<image :src="item.image || ''" mode=""></image>
			<text>{
   
   { item.title || '' }}</text>
		</view>
	</block>
</view>
const query = uni.createSelectorQuery().in(this);
query.select('.square_giant').boundingClientRect(({ height }) => {
  console.log('square_giant的高度是:' + height + 'px');
}).exec();

 

Guess you like

Origin blog.csdn.net/weixin_46167462/article/details/130650293