W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗(yàn)值獎勵
解釋:停止監(jiān)聽羅盤數(shù)據(jù)。
Object object
屬性名 | 類型 | 必填 | 默認(rèn)值 | 說明 |
---|---|---|---|---|
success | Function | 否 | 接口調(diào)用成功的回調(diào)函數(shù) | |
fail | Function | 否 | 接口調(diào)用失敗的回調(diào)函數(shù) | |
complete | Function | 否 | 接口調(diào)用結(jié)束的回調(diào)函數(shù)(調(diào)用成功、失敗都會執(zhí)行) |
<view class="card-area">
<view class="wrap">
<view class="page-top">
<view class="tip-week">{{title}}</view>
</view>
<view class="direction">
<view class="bg-compass-line"></view>
<view class="bg-compass" style="transform: rotate(-{{direction}}deg)">
<view class="num num0" style="transform: rotate({{direction}}deg)">0</view>
<view class="num num90" style="transform: rotate({{direction}}deg)">90</view>
<view class="num num180" style="transform: rotate({{direction}}deg)">180</view>
<view class="num num270" style="transform: rotate({{direction}}deg)">270</view>
</view>
<div class="cg-wrap">
<div class="circle-left-wrap"><div class="circle-left" style="transform:rotate({{leftdeg}}deg);transform-origin:50% 50%"></div></div>
<div class="circle-right-wrap"><div class="circle-right" style="transform:rotate({{rightdeg}}deg);transform-origin:50% 50%"></div></div>
<div class="mask">
<view class="direction-num">
<text>{{direction}}</text>
<text class="direction-degree"></text>
</view>
</div>
</div>
</view>
<view class="page-body-btn">
<view class="middle-btn {{!isWatch ? '' : 'disabled'}}" bind:tap="startWatch">開始監(jiān)聽</view>
<view class="middle-btn {{!isWatch ? 'disabled' : ''}}" bind:tap="stopWatch">停止監(jiān)聽</view >
</view>
</view>
</view>
Page({
data: {
title: '旋轉(zhuǎn)手機(jī)即可獲取方位信息',
direction: 0,
isWatch: true,
leftdeg: 0,
rightdeg: 0
},
onReady() {
swan.onCompassChange(res => {
this.setData({
direction: parseInt(res.direction, 10)
});
this.updateProgress(res.direction);
});
},
onShow() {
let isWatch = this.data.isWatch;
isWatch ? swan.startCompass() : swan.stopCompass();
},
startWatch() {
this.setData('isWatch', true);
swan.startCompass();
},
stopWatch() {
this.setData('isWatch', false);
swan.stopCompass();
},
updateProgress(direction) {
let leftdeg;
let rightdeg;
let deg = +direction;
if (deg > 180) {
leftdeg = 180;
rightdeg = 180 - deg;
}
else {
leftdeg = -deg;
rightdeg = 0;
}
this.setData({
leftdeg,
rightdeg
});
}
});
Copyright©2021 w3cschool編程獅|閩ICP備15016281號-3|閩公網(wǎng)安備35020302033924號
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號
聯(lián)系方式:
更多建議: