Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/google-chrome/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Chrome桌面中的ondevicemotion返回true_Javascript_Google Chrome - Fatal编程技术网

Javascript Chrome桌面中的ondevicemotion返回true

Javascript Chrome桌面中的ondevicemotion返回true,javascript,google-chrome,Javascript,Google Chrome,我使用的是github的一个shake函数,它有一个基于浏览器的javascript检测 //feature detect this.hasDeviceMotion = 'ondevicemotion' in window; 尽管如此,即使在OSX上的Chrome上,这一点也是正确的。 感觉很奇怪,因为我不愿意在桌面上晃动显示器 OSX上的Safari在测试时返回false 我已经搜索过了,但无法找到Chrome决定走这条路的原因。这让我讨厌 是否有更好的方法进行此检测?并非所有移动设备都有震

我使用的是github的一个shake函数,它有一个基于浏览器的javascript检测

//feature detect
this.hasDeviceMotion = 'ondevicemotion' in window;
尽管如此,即使在OSX上的Chrome上,这一点也是正确的。 感觉很奇怪,因为我不愿意在桌面上晃动显示器

OSX上的Safari在测试时返回false

我已经搜索过了,但无法找到Chrome决定走这条路的原因。这让我讨厌


是否有更好的方法进行此检测?并非所有移动设备都有震动功能。。或者不让浏览器具有这种功能,因为它在windows Phone中似乎不起作用。

对您的问题也不是很确定,我只是在深入研究它的功能,但是您可以使用类似

X : <span id="varx"></span>
Y : <span id="vary"></span>
Z : <span id="varz"></span>
<script>
    window.ondevicemotion = function(event){
        var accelerationX = event.accelerationIncludingGravity.x;
        var accelerationY = event.accelerationIncludingGravity.y;
        var accelerationZ = event.accelerationIncludingGravity.z;

        document.getElementById("varx").innerHTML = accelerationX;
        document.getElementById("vary").innerHTML = accelerationY;
        document.getElementById("varz").innerHTML = accelerationZ;
    };
</script>
只有当事件具有accelerationIncludingGravity属性时,它才会显示此值,这仅在移动设备中可用,而不是100%这是您想要的,您还可以触发一个事件,询问ifaccelerationX{//execute action}否则{//execute planB}希望这有帮助,如果没有,我很乐意学习并获得一些反馈