Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width">
  <title>JS Bin</title>
</head>
<body>
  <h4>Orientace:</h4>
  <div id="i"></div>
  <br>
  <h4>Aktuální zrychlení:</h4>
  <div id="j"></div>
  <br>
  <h4>Nejvyšší zrychlení:</h4>
  <div id="k"></div>
</body>
</html>
 
const out = (s, e) => document.querySelector(e).innerHTML = `${s}<br>`
if (window.DeviceOrientationEvent) {
  
  window.addEventListener('deviceorientation', (e) => {
    let alpha = Math.round(e.alpha),
        beta = Math.round(e.beta),
        gamma = Math.round(e.gamma)
    
    out(`Alfa: ${alpha}&deg;<br>Beta: ${beta}&deg;<br>Gamma: ${gamma}&deg;`, '#i')
  }, false)
  
}
if (window.DeviceMotionEvent) {
  
  let max = {
    x: 0, 
    y: 0, 
    z: 0
  }
  
  window.addEventListener('devicemotion', (e) => {
    let x = Math.round(e.acceleration.x), 
        y = Math.round(e.acceleration.y), 
        z = Math.round(e.acceleration.z)
    
    out(`X: ${x} m/s&sup2;<br>Y: ${y} m/s&sup2;<br>Z: ${z} m/s&sup2;`, '#j')
    
    if (x > max.x) {
      max.x = x;
    }
    if (y > max.y) {
      max.y = y;
    }
    if (z > max.z) {
      max.z = z;
    }
    
    out(`mX: ${max.x} m/s&sup2;<br>mY: ${max.y} m/s&sup2;<br>mZ: ${max.z} m/s&sup2;`, '#k')
  
  })
}
Output 300px

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
tichopadpro
0viewers