700字范文,内容丰富有趣,生活中的好帮手!
700字范文 > 小程序获取元素宽高

小程序获取元素宽高

时间:2018-08-23 22:54:58

相关推荐

小程序获取元素宽高

赋值:直接就是px

<view class="wrap_box" style="{{Pick?'padding-top:'+ewmHeight+'px;':''}}">

//获取元素宽度高度 都是px为单位

第一种 推荐://二维码高度getewmHeight(){var that = this;//创建节点选择器var query = wx.createSelectorQuery();//选择class idquery.select('.class').boundingClientRect(function (rect) {console.log('二维码-->', rect) //{bottom: 378, height: 367, id: "ewm", left: 11.5 ...}that.setData({ewmHeight: rect.height})}).exec();},第二种:onLoad: function () {let _this = this;const query = wx.createSelectorQuery();query.select('#id').boundingClientRect();query.exec(function (res) { //[{bottom: 378,id: "ewm",}]console.log('打印宽度', res[0].height);let dheight = parseInt(res[0].height);_this.setData({ewmHeight:dheight})})},

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。