Note that there are some explanatory texts on larger screens.

plurals
  1. POAccelerometer not working in Firefox (works in Chrome)
    primarykey
    data
    text
    <p>This is my HTML:</p> <pre><code>&lt;div class="sl-slide bg9" id="slide9"&gt; &lt;div class="bg9-content"&gt; &lt;header&gt; &lt;h1&gt;&lt;/span&gt;Accelerometer&lt;/h1&gt; &lt;p&gt;Move your laptop to guide the circle into it's place&lt;/p&gt; &lt;div class="how-it-works" ng-click="go('/learn/getting-started-with-html5/accelerometer-how-it-works')"&gt;See how it works&lt;/div&gt; &lt;/header&gt; &lt;div class="accelerometer-game"&gt; &lt;div class="accelerometer-game-board rotated-square-large"&gt; &lt;div class="accelerometer-game-ball" id="game-ball"&gt;&lt;/div&gt; &lt;div class="accelerometer-game-goal"&gt;&lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>This is my JavaScript:</p> <pre><code>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 &gt; 40 &amp;&amp; (tiltLR &gt;= -5 &amp;&amp; tiltLR &lt;= 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! &lt;br&gt;Device orientation is not supported on your browser."); } }); </code></pre> <p>I accessing the accelerometer from within an Angular controller. I am using Firefox 26, which <a href="http://caniuse.com/#feat=deviceorientation" rel="nofollow">supports device orientation events</a>. </p> <p>When I look at the logging in Firefox's Browser Console, I see the following <code>console.logs()</code>:</p> <ul> <li>"Angular accelerometer controller being called" </li> <li>"Device Orientation if statement being called from controller"</li> </ul> <p>I DO NOT see <code>console.log('device orientation handler fx being called!');</code> and I don't know why that fx is not being called.</p> <p>NOTE: The following JavaScript works in the Chrome DevTools console, but returns <code>null</code> when typed in to Firefox's Browser Console:</p> <p><code>document.getElementById('game-ball');</code></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload