accelerometer - JavaScript addEventListener delay -


I am creating a mobile application using Javascript. I need to get the data from the phone's accelerometer, so I want to attach it to an event listener:

  if (window.DeviceOrientationEvent) {window.addEventListener ("deviceorientation" , Function (event) {If (typeof (event.alpha)! = 'Undefined') {// Here is the event for an event}}, false); }   

But the problem is that it receives data in every millisecond, so when I call to attract and redraw some according to this data, then It is every millisecond - & gt; The app crashes.

Is there a way to delay, or to get this data in a small part? For example, is there a function for every half-second to hear any function?

In this "function debuting", you execute your goods only once Are there. A simple implementation would be:

  var lastExecution; AddEventListener ("deviceorientation", function) {var now = Date.now (); if (now - last exec & lt; 17) returns; // ~ 60Hz lastExecution = now; ...}, false);   

(Yes, the last implementation is mandatory at first. That's okay.)

Comments

Popular posts from this blog

Pass DB Connection parameters to a Kettle a.k.a PDI table Input step dynamically from Excel -

multithreading - PhantomJS-Node in a for Loop -

c++ - MATLAB .m file to .mex file using Matlab Compiler -