返回顶部

动态获取设备的信息,然后设置相应的wxss样式

动态获取设备的高度,然后再wxss中设置高度

使用 getSystemInfoSync() 来获取设备信息......  https://developers.weixin.qq.com/miniprogram/dev/api/base/system/system-info/wx.getSystemInfo.html

1 <scroll-view class="scroll-view" scroll-y="true" style="height:{{winHeight}}px">
2 
3 </scroll-view>
index.wxml
1 .scroll-view{
2     width: 100%; 
3     /* height: 500px;   写到wxml 的 style中了 */
4     background-color: cyan; 
5 }
index.wxss
 1 Page({
 2  
 3     /**
 4      * 页面的初始数据
 5      */
 6     data: {
 7 
 8     },
 9 
10     /**
11      * 生命周期函数--监听页面加载
12      */
13     onLoad: function (options) {
14         var systemInfo = wx.getSystemInfoSync(); 
15         console.log(systemInfo);  
16         var winHeight = systemInfo.windowHeight; 
17         var winWidth = systemInfo.windowWidth;  
18         this.setData({
19             winWidth:winWidth,
20             winHeight:winHeight
21         });
22 
23     },
24 })
index.js

 

posted @ 2019-10-30 21:14  Zcb0812  阅读(274)  评论(0)    收藏  举报