uniapp gets the width, height and position of the top, bottom, left, and right borders of the view

<view class="cont-box"></view>
/* 获取节点信息的对象 */
getElementRect() {
  const query = uni.createSelectorQuery().in(this);
  query
    .select(".cont-box")
    .boundingClientRect(res => {
      console.log(res);
      console.log(res.height); // 102.85714721679688
    })
    .exec();
}

The res result returned by boundingClientRect (in pixels [px])

Attributes type illustrate
id String ID of the node
dataset Object node's dataset
left Number Node's left border coordinates
right Number The coordinates of the right border of the node
top Number Coordinates of the upper boundary of the node
bottom Number Node's lower boundary coordinates
width Number node width
height Number node height

For more information, please refer to: uni.createSelectorQuery() | uni-app official website

Guess you like

Origin blog.csdn.net/AdminGuan/article/details/132246536