如何基于var值运行Open.window事件

时间:2016-08-01 20:32:49

标签: javascript mobile gyroscope

以下是我的代码的链接:www.parallaxplayground.com/flipside.html 我在尝试使用手机陀螺仪创建的变量翻转用户手机时尝试打开新网页。



        <script>
function init() {
  //Find our div containers in the DOM
  var dataContainerOrientation = document.getElementById('dataContainerOrientation');
  var dataContainerMotion = document.getElementById('dataContainerMotion');
 
 
  //Check for support for DeviceOrientation event
  if(window.DeviceOrientationEvent) {
    window.addEventListener('deviceorientation', function(event) {
            var alpha = event.alpha;
            var beta = event.beta;
            var gamma = event.gamma;
           
            if(alpha!=null || beta!=null || gamma!=null) 
              dataContainerOrientation.innerHTML = 'alpha: ' + alpha + '<br/>beta: ' + beta + '<br />gamma: ' + gamma;
          }, false);
  }
  
 
 
  // Check for support for DeviceMotion events
  if(window.DeviceMotionEvent) {
  window.addEventListener('devicemotion', function(event) {
            var x = event.accelerationIncludingGravity.x;
            var y = event.accelerationIncludingGravity.y;
            var z = event.accelerationIncludingGravity.z;
            
            var r = event.rotationRate;
            var html = 'Acceleration:<br />';
            html += 'x: ' + x +'<br />y: ' + y + '<br/>z: ' + z+ '<br />';
            html += 'Rotation rate:<br />';
            if(r!=null) html += 'alpha: ' + r.alpha +'<br />beta: ' + r.beta + '<br/>gamma: ' + r.gamma + '<br />';
            if (y > 7)   
        	{  
            	window.open("http://www.w3schools.com");
            	};
            dataContainerMotion.innerHTML = html;     
            
          });
  }
  
 
}   
</script>
&#13;
&#13;
&#13;

您必须在手机上进行测试。感谢您提供的任何帮助!

0 个答案:

没有答案