Javascript 加速计在Firefox中不工作(在Chrome中工作)
这是我的HTML:Javascript 加速计在Firefox中不工作(在Chrome中工作),javascript,css,html,angularjs,accelerometer,Javascript,Css,Html,Angularjs,Accelerometer,这是我的HTML: <div class="sl-slide bg9" id="slide9"> <div class="bg9-content"> <header> <h1></span>Accelerometer</h1> <p>Move your laptop to guide the circle into it's place&l
<div class="sl-slide bg9" id="slide9">
<div class="bg9-content">
<header>
<h1></span>Accelerometer</h1>
<p>Move your laptop to guide the circle into it's place</p>
<div class="how-it-works" ng-click="go('/learn/getting-started-with-html5/accelerometer-how-it-works')">See how it works</div>
</header>
<div class="accelerometer-game">
<div class="accelerometer-game-board rotated-square-large">
<div class="accelerometer-game-ball" id="game-ball"></div>
<div class="accelerometer-game-goal"></div>
</div>
</div>
</div>
</div>
加速计
移动你的笔记本电脑,引导圆圈进入它的位置
看看它是如何工作的
这是我的JavaScript:
HTML5GuideApp.controller('accelerometerCtrl', function($scope){
console.log('Angular accelerometer controller being called');
// Accelerometer
function deviceOrientationHandler(tiltLR, tiltFB, dir){
console.log('device orientation handler fx being called!');
var ball = document.getElementById('game-ball');
// move the game ball
ball.style.webkitTransform = "translate("+ tiltLR +"px, "+ (tiltFB*2) + "px)";
ball.style.MozTransform = "translate("+ tiltLR +"px, "+ (tiltFB*2) + "px)";
ball.style.transform = "translate("+ tiltLR +"px, "+ (tiltFB*2) + "px)";
}
// test for support
if(window.DeviceOrientationEvent){
console.log('Device Orientation if statement being called from controller!');
// listen for the deviceOrientation event and handle the raw data
// FIREFOX PROBLEM IS HERE. addEventListener is not being called :(
window.addEventListener('deviceorientation', function(eventData){
// gamma is the left-to-right tilt in degrees, where right is positive
var tiltLR = eventData.gamma;
// beta is the front-to-back title in degrees, where front is positive
var tiltFB = eventData.beta;
// alpha is the compass direction the device is facing in degrees
var dir = eventData.alpha;
// call our orientation event handler
deviceOrientationHandler(tiltLR, tiltFB, dir);
// victory condition
if(tiltFB > 40 && (tiltLR >= -5 && tiltLR <= 5)){
console.log('VICTORY CONDITION TEXT');
$('header p').text('You win!').css('text-indent', '-52px');
}
}, false);
} else {
$('header p').html("Sorry, you can't play the game! <br>Device orientation is not supported on your browser.");
}
});
HTML5GuideApp.controller('AccelerometrCtrl',函数($scope){
log('调用角加速度计控制器');
//加速计
功能设备定向处理程序(tiltLR、tiltFB、dir){
log('正在调用的设备方向处理程序fx!');
var ball=document.getElementById('game-ball');
//移动游戏球
ball.style.webkitttransform=“translate(“+tiltLR+”px,”+(tiltFB*2)+“px)”;
ball.style.MozTransform=“translate(“+tiltLR+”px,”+(tiltFB*2)+“px)”;
ball.style.transform=“translate”(+tiltLR+“px”,+(tiltFB*2)+“px)”;
}
//支持测试
if(window.DeviceOrientationEvent){
log('Device Orientation if statement be called from controller!');
//侦听deviceOrientation事件并处理原始数据
//FIREFOX存在问题。未调用addEventListener:(
window.addEventListener('deviceorientation',函数(eventData){
//gamma是以度为单位的从左向右倾斜,其中right为正值
var tiltLR=eventData.gamma;
//beta是以度为单位的前后标题,其中正面为正
var tiltFB=eventData.beta;
//alpha是设备面对的指南针方向,单位为度
var dir=eventData.alpha;
//调用我们的定向事件处理程序
设备定向处理器(tiltLR、tiltFB、dir);
//胜利条件
如果(倾斜FB>40&&(倾斜LR>=-5&&tiltLR