JavaScript Smooth DeviceOrientation Values

I'm trying to shift an image around based on the device orientation. But the values are very jumpy at rest, going between -1 to +2 with no movement, and I need a way to smooth it out a bit.

Is there an easy way to make this less jittery by averaging it out or something?

 init();
    var count = 0;

    function init() {
      if (window.DeviceOrientationEvent) {


        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 tilt 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);
          }, false);
      } 
    }

    function deviceOrientationHandler(tiltLR, tiltFB, dir) {

      var logo = document.getElementById("imgLogo");
      logo.style.webkitTransform = "rotate("+ tiltLR +"deg) rotate3d(1,0,0, "+ (tiltFB*-1)+"deg)";
      logo.style.MozTransform = "rotate("+ tiltLR +"deg)";
      logo.style.transform = "rotate("+ tiltLR +"deg) rotate3d(1,0,0, "+ (tiltFB*-1)+"deg)";
    }

http://codepen.io/picard102/pen/zvOVLx

Answer:1

I've used jQuery version 2.2.4 and tried to capture event - no luck. Is there any way to fix issue? This code works: window.addEventListener('test.namespace', e => console.log('CustomEvent with ...

I've used jQuery version 2.2.4 and tried to capture event - no luck. Is there any way to fix issue? This code works: window.addEventListener('test.namespace', e => console.log('CustomEvent with ...

  1. dispatch custom event with data

I have a 3 block of image. I want a css in which hover a block A transform block C and B, hovering a block B transform block A and C or hovering a block C transform block A and B You can see a demo ...

I have a 3 block of image. I want a css in which hover a block A transform block C and B, hovering a block B transform block A and C or hovering a block C transform block A and B You can see a demo ...

var developers = [ { name: "Joe", age: 23 ,overallLevel: "high"}, { name: "Sue", age: 28 ,overallLevel: "advanced" }, { name: "Jon", age: 32 ,overallLevel: "high" }, { name: "Bob", age:...

var developers = [ { name: "Joe", age: 23 ,overallLevel: "high"}, { name: "Sue", age: 28 ,overallLevel: "advanced" }, { name: "Jon", age: 32 ,overallLevel: "high" }, { name: "Bob", age:...

  1. javascript code count
  2. countdown javascript code
  3. javascript code to count the number of elements in a form
  4. javascript code to count number of visitors
  5. javascript code to count characters in textbox
  6. javascript code to count number of words
  7. javascript code for word count
  8. javascript code for character count
  9. write javascript code to count sum of digits

I have a time/date string that is returned like so: "5/31/2016, 2:23:33 PM". I need only the HH:MM and am/pm, so 2:23 PM I am able to split the date off but not sure how I can remove the colon and ...

I have a time/date string that is returned like so: "5/31/2016, 2:23:33 PM". I need only the HH:MM and am/pm, so 2:23 PM I am able to split the date off but not sure how I can remove the colon and ...

  1. javascript slice time complexity
  2. slice time javascript