欢迎光临,了解微信小程序开发,就上易用通!

利用screenWidth与screenHeight手算布局

发布:2018-01-25 09:39浏览: 来源:网络 作者:tianshu

在app.js中获取到设备宽高

 

  1. // 设备信息
  2. wx.getSystemInfo({
  3. success: function(res) {
  4. that.screenWidth = res.windowWidth;
  5. that.screenHeight = res.windowHeight;
  6. that.pixelRatio = res.pixelRatio;
  7. }
  8. });

然后挖坑在布局页面

 

  1. <view class="sidebar" style="height: {{sidebarHeight}}px;">
  2. <dt>
  3. <image src="{{item.avatar.attributes.url}}" mode="scaleToFit" bindtap="avatarTap" data-object-id="{{item.objectId}}" style="width:{{imageWidth}}px; height: {{imageWidth}}px;"/>
  4. </dt>

最后在js中实现数值

 

  1. setImageWidth: function () {
  2. var screenWidth = getApp().screenWidth;
  3. var imageWidth = (screenWidth - 130) / 3;
  4. this.setData({
  5. imageWidth: imageWidth
  6. });
  7. },
  8. setSideHeight: function () {
  9. this.setData({
  10. sidebarHeight: getApp().screenHeight
  11. });
  12. },

如图:

利用screenWidth与screenHeight手算布局(图1)

 

源码下载:https://git.oschina.net/dotton/lendoo-wx





免责声明:本站所有文章和图片均来自用户分享和网络收集,文章和图片版权归原作者及原出处所有,仅供学习与参考,请勿用于商业用途,如果损害了您的权利,请联系网站客服处理。