微信小程序
-
按钮宽度设置
// 1 样式 width中加入!important .centerX{ margin-top: 90px; background-color: #2F91FF; border-radius: 22.5px; height: 45; width: fit-content !important; // 加入!important font-size: 15px; color: white; font-style: normal; } // 2 button 加入style 内容和样式中一致 .centerX{ margin-top: 90px; background-color: #2F91FF; border-radius: 22.5px; height: 45; width: fit-content; font-size: 15px; color: white; font-style: normal; } <button id="search" class="centerX" style="width: fit-content">搜索</button>
-
控件叠加 居中 View
/* View 样式 子视图在父视图中叠加效果 父视图 position: relative; z-index: 1; 子视图 position: absolute; z-index: 1; 子视图在父视图中居中 父视图样式 display: flex; align-items: center; justify-content: center; */ .headView{ margin-top: 10px; width: 100% !important; height: 270px; background-color: white; position: relative; z-index: 1; display: flex; align-items: center; justify-content: center; } .search-button{ position: absolute; z-index: 1; background-color: #2F91FF; border-radius: 22.5px; height: 45; width: fit-content !important; font-size: 15px; color: white; font-style: normal; margin-top: 0px; } .circle-image{ position: absolute; z-index: 1; } .circle-image imageSize { width: 225; height: 226; }
-
页面滚动 计算滚动区域
<scroll-view class="scrollView" scroll-y="true" scroll-top="{{scrollTop}}" style="height:{{clientHeight}}px;">
let screenH = wx.getSystemInfoSync().windowHeight; let query = wx.createSelectorQuery().in(that); query.select('.headView').boundingClientRect(); query.exec(res => { let headH = res[0].height; let scrollHeight = screenH - headH - 10; // 滚动区域高度 console.log('can scroll height is ' + scrollHeight); that.setData({ clientHeight: scrollHeight }) })
-
控件水平居中对齐
-
父视图 align-items: center; justify-content: center; display: flex;
.peripheralView { height: 50px; margin-left: 15px; align-items: center; justify-content: center; display: flex; }
-
子视图 align-items: center; justify-content: center; 居左或者居右对齐 position: absolute; left(right): 15px;
.peripheralLabel { align-items: center; justify-content: center; font-size: 15px; color: #2F91FF; width: auto !important; height: 45; position: absolute; // 居左对齐 left: 15px; /* 靠左调节 */ margin-top: 10px; /* text-align: center; */ } .connect-Button { margin-top: 10px; position: absolute; right: 20px; /* 靠右调节 */ background-color: #2F91FF; border-radius: 22.5px; height: 45; width: auto !important; font-size: 15px; color: white; font-style: normal; align-items: center; justify-content: center; text-align: center; }
-
-
列表
<view wx:for="{{peripheralArr}}" wx:for-item="item" wx:key="*this" class="peripheralView" bindtap="connectPeripheral" data-item="{{item}}"> <text class="peripheralLabel" >{{item.name}}</text> <button id="connect" class="connect-Button">连接</button> </view>
data: { peripheralArr:[], }, wx.getBluetoothDevices({ success: function (res){ console.log("success get "); // var height = 50 * res.devices.length; // console.log("height value " + height); that.setData({ peripheralArr:res.devices.filter(item => item.name.indexOf("KS") != -1) // clientHeight: height }); // console.log(that.data.peripheralArr); }, fail(err){ // console.log("get bluetooth" + err); }, complete(res){ // console.log("get bluetooth" + res); } })