當(dāng)前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
javascript检查移动设备是否支持重力方向感应
生活随笔
收集整理的這篇文章主要介紹了
javascript检查移动设备是否支持重力方向感应
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
javascript如何檢查移動設(shè)備,如手機(jī)平臺是否支持重力或者方向感應(yīng)。可以使用html5提供的重力和方向感應(yīng)接口來判斷。html5 中針對高端手機(jī)提供了重力感應(yīng)和重力加速的接口,開發(fā)可以利用這個接口獲取到移動設(shè)備重力加速感應(yīng)數(shù)據(jù)。目前已經(jīng)支持的瀏覽器只有chrome和firefox,以及IOS的webkit(貌似android上因?yàn)榘姹静町惡艽?#xff0c;部分低版本的系統(tǒng)不支持)。引用來源:http://www.pjhome.net/article/Javascript/html5_Orientation.html
javascript檢查移動設(shè)備是否支持重力方向感應(yīng)源代碼如下-收縮HTML代碼 運(yùn)行代碼 [如果運(yùn)行無效果,請自行將源代碼保存為html文件運(yùn)行]
<title>javascript檢查移動設(shè)備是否支持重力方向感應(yīng)</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('設(shè)備支持重力感應(yīng)|'));}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('設(shè)備支持方向感應(yīng)'));}}window.addEventListener('deviceorientation', orientationListener, false); //方向感應(yīng)器 window.addEventListener('MozOrientation', orientationListener, false); //方向感應(yīng)器 for firefox window.addEventListener('devicemotion', orientationListener, false); //重力加速感應(yīng)器 for iphone, android
</script>
?
轉(zhuǎn)載于:https://www.cnblogs.com/yzryc/p/6249349.html
總結(jié)
以上是生活随笔為你收集整理的javascript检查移动设备是否支持重力方向感应的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 怎么批量给图片加纯色边框?
- 下一篇: html背景边框特效代码,纯JS实现动态