zoukankan      html  css  js  c++  java
  • javascript检查移动设备是否支持重力方向感应

     javascript如何检查移动设备,如手机平台是否支持重力或者方向感应。
    
      可以使用html5提供的重力和方向感应接口来判断。
    
      html5 中针对高端手机提供了重力感应和重力加速的接口,开发可以利用这个接口获取到移动设备重力加速感应数据。
    
      目前已经支持的浏览器只有chrome和firefox,以及IOS的webkit(貌似android上因为版本差异很大,部分低版本的系统不支持)。
    
    引用来源:http://www.pjhome.net/article/Javascript/html5_Orientation.html
    
      javascript检查移动设备是否支持重力方向感应源代码如下
    
    -收缩HTML代码  运行代码  [如果运行无效果,请自行将源代码保存为html文件运行]
    <title>javascript检查移动设备是否支持重力方向感应</title>
    <script>
        var supportDevicemotion=false,supportOrientation=false;
        function orientationListener(e) {
            if (e.type == 'devicemotion') {
                supportDevicemotion = true;
                window.removeEventListener('devicemotion', orientationListener, false);
                document.body.appendChild(document.createTextNode('设备支持重力感应|'));
            }
            else if (e.type == 'deviceorientation' || e.type.toLowerCase() == 'mozorientation') {
                supportOrientation = true;
                window.removeEventListener('deviceorientation', orientationListener, false);
                window.removeEventListener('MozOrientation', orientationListener, false);
                document.body.appendChild(document.createTextNode('设备支持方向感应'));
            }
        }
        window.addEventListener('deviceorientation', orientationListener, false); //方向感应器  
        window.addEventListener('MozOrientation', orientationListener, false); //方向感应器 for firefox      
        window.addEventListener('devicemotion', orientationListener, false); //重力加速感应器 for iphone, android
    </script>
  • 相关阅读:
    live555学习之RTSP连接建立以及请求消息处理过程
    RTSP协议学习笔记
    RTP头结构解析
    Doubango ims 框架 分析之 多媒体部分
    VMware虚拟机 NAT模式 配置静态ip
    计算机网络: IP地址,子网掩码,网段表示法,默认网关,DNS服务器详解
    VMWare VMNet 8 的配置使用
    VMware虚拟机CentOS7
    如何禁止虚拟机自动获取DHCP分配的ip地址
    Linux之VMware虚拟机取消DHCP
  • 原文地址:https://www.cnblogs.com/yzryc/p/6249349.html
Copyright © 2011-2022 走看看