我试图在移动 Safari 的屏幕上显示我从模板函数返回的结果。我可以看到我的设备支持 devicemotion 我可以看到我的 vartiltFB 的控制台日志和数据
我看不到或无法工作的是它在我的移动 safari 上的 html 屏幕上显示。
Template.tapapp.showAngle = function() {
var tiltFB;
if (window.DeviceMotionEvent) {
window.addEventListener('devicemotion', deviceMotionHandler, false);
console.log("Devicemotion IS supported on your device.");
} else {
console.log("Devicemotion Not supported on your device.");
return "Devicemotion Not supported on your device.";
}
function deviceMotionHandler(eventData) {
var acceleration = eventData.accelerationIncludingGravity;
var rawAcceleration = "[" + Math.round(acceleration.x) + ", " + Math.round(acceleration.y) + ", " + Math.round(acceleration.z) + "]";
var facingUp = -1;
if (acceleration.z > 0) {
facingUp = +1;
}
tiltFB = Math.round(((acceleration.y + 9.81) / 9.81) * 90 * facingUp);
console.log(tiltFB);
//Meteor.defer(function () {
// $('#angel').html(tiltFB);
// return tiltFB;
});
return tiltFB;
}
};
这是我的html:
<template name="tapapp">
<div class="container">
<h3 class="angel-class" id="angle">{{showAngle}}</h3>
</template>