W3Cschool
恭喜您成為首批注冊(cè)用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
解釋: 執(zhí)行所有的請(qǐng)求,請(qǐng)求結(jié)果按請(qǐng)求次序構(gòu)成數(shù)組,在 callback 的第一個(gè)參數(shù)中返回。
Function callback
<view class="wrap">
<view class="card-area">
<movable-area>
<movable-view class="target" x="{{x}}" y="{{y}}" direction="all" bindchange="queryNodeInfo">
Drag
</movable-view>
</movable-area>
<view s-for="item in metrics" class="list-area border-bottom">
<text class="list-item-key-4">{{item.key}}</text>
<text class="list-item-value">{{item.val}}</text>
</view>
</view>
</view>
Page({
data: {
metrics: []
},
onReady() {
this.queryNodeInfo();
},
queryNodeInfo() {
const query = swan.createSelectorQuery();
query.select('.target').boundingClientRect();
query.exec(res => {
console.log('節(jié)點(diǎn)信息:', res[0]);
const rect = res[0];
if (rect) {
const metrics = []
for (const key in rect) {
if (key !== 'id' && key !== 'dataset') {
const val = rect[key];
metrics.push({key, val});
}
}
this.setData({metrics});
}
});
}
});
movable-view {
display: flex;
align-items: center;
justify-content: center;
height: 100rpx;
width: 100rpx;
background: #38f;
color: #fff;
}
movable-area {
height: 400rpx;
width: 400rpx;
background-color: #ccc;
overflow: hidden;
}
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: