我们在开发微信小程序的时候,经常需要获取小程序当前的屏幕高度,这个功能需求看起来不是很难,但是也有一些点需要我们注意的,那么我们要怎么获取微信小程序屏幕高度呢?今天厦门在乎科技为大家带来微信小程序获取屏幕高度方法,一起来了解一下吧。
微信小程序获取屏幕高度方法一:
onload:function(){
this.setdata({
height:wx.getsysteminfosync().windowheight,
width:wx.getsysteminfosync().windowwidth
})
}
微信小程序获取屏幕高度方法二:
.index{
height:100vh;
width:100vw;
}
#css3引入的"vw"和"vh"基于宽度/高度相对于窗口大小
#"vw"="viewwidth""vh"="viewheight"
微信小程序获取屏幕高度方法三:
letthat=this;
//获取系统信息
wx.getsysteminfo({
success:function(res){
//获取可使用窗口宽度
letclientheight=res.windowheight;
//获取可使用窗口高度
letclientwidth=res.windowwidth;
//算出比例
letratio=750/clientwidth;
//算出高度(单位rpx)
letheight=clientheight*ratio;
//设置高度
that.setdata({
height:height
});
}
});
方法四:获取微信小程序内元素高度
constquery=wx.createselectorquery()//定义query
query.select('#txt_medium').boundingclientrect()//获取元素参数
query.exec((res)=>{
console.log(res)//可以得到元素高度、距离顶部的top值、宽度等,单位为px
})
方法五:获取微信小程序屏幕高度和宽度,单位:px
height:wx.getsysteminfosync().windowheight,
width:wx.getsysteminfosync().windowwidth
以上就是今天为大家带来的关于“微信小程序获取屏幕高度小程序屏幕高度怎么获取”全部内容,整体来说,难度不是很大,对于获取小程序屏幕宽度也是同理,想要了解更多关于小程序开发运营的内容,欢迎关注厦门在乎科技-专注小程序、app、网站开发