Firefox中的“deviceorientation”? [英] 'deviceorientation' in Firefox?

查看:218
本文介绍了Firefox中的“deviceorientation”?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在笔记本电脑上使用'deviceorientation', jsfiddle 的示例似乎工作正常在Chrome中,但在Firefox中没有响应。我认为JS的第15行无法正常工作......

I'm working with 'deviceorientation' on my laptop and an example jsfiddle seems to work fine in Chrome but is not responding in Firefox. I think that line 15 of JS is not working somehow...

window.addEventListener('deviceorientation', devOrientHandler, false);

第18行的MozOrientation版本似乎没有懈怠

The MozOrientation version on line 18 doesn't seem to be picking up the slack

window.addEventListener('MozOrientation', mozDevOrientHandler, false);

刚更新的Firefox。没有变化。我试图在台式机上进行测试,并且(不出所料)机器似乎没有必要的加速度计/传感器,因此小提琴不适用于该机器上的任何浏览器。我一直在搜索问题,阅读w3c规范, MDN支持而我仍然无法得到它。

Just updated Firefox. And no change. I've tried to test on a desktop and (unsurprisingly) the machine doesn't seem to have the necessary accelerometers/sensors so the fiddle doesn't work on any browser on that machine. I've been scouring questions, reading the w3c specs, the MDN support and I still can't get it.

有人知道这是否是Firefox问题?我搞砸了设置还是什么?任何帮助深表感谢。关于为什么这个示例jsfiddle不能在Firefox上运行的任何想法?
注意:上面MDN链接中的绿球示例也不适用于FF。第一次问SO的问题。

Does anybody know if this is a Firefox issue? Did I mess up settings or something? Any help is much appreciated. Any ideas as to why that example jsfiddle isn't working on Firefox? note: the example "green ball" in the MDN link above isn't working on FF either. First time asking a question on SO.

谢谢!

编辑:我应该澄清一下jsfiddle是我能找到的最好的例子,而且是不是我的代码。我相信这是来自HTML5rocks.com,但我找不到这个来源。

I should clarify that the jsfiddle is the best example I could find, and is NOT my code. I believe it was from HTML5rocks.com but I can't find that source.

推荐答案

在撰写本文时,Firefox不公开 DeviceOrientation 任何桌面平台上的事件。您的事件处理程序不会在Firefox中触发,因为它们的桌面浏览器版本中未启用API。

Firefox does not, at this time of writing, expose DeviceOrientation events on any Desktop platform. Your event handler is not triggered in Firefox simply for the reason that the API is not enabled in their Desktop browser builds.

另一方面,基于Chromium的浏览器启用了DeviceOrientation事件,但有一些重要的警告。由于Apple计算机中可用的陀螺仪+加速计硬件传感器的普遍可用性,基于铬的浏览器通常仅在Mac OS X上一致地返回DeviceOrientation事件。此外,基于Chromium的浏览器将 event.alpha 值报告为 undefined ,因为没有可用的罗盘或磁传感器正确计算。

On the other hand, Chromium-based browsers have enabled DeviceOrientation events with some important caveats. Chromium-based browsers generally only return DeviceOrientation events consistently on Mac OS X due to the general availability of gyro + accelerometer hardware sensors that are available in Apple computers. Additionally, Chromium-based browsers report the event.alpha value as undefined due to no compass or magnetic sensors being available to compute that correctly.

移动浏览器的情况要好得多,可以说是这个API的主要目标。所有主要的移动浏览器(iOS上的Safari,Android上的Chrome / Opera / Firefox)都以其无前缀形式支持此事件,即 window.addEventListener('deviceorientation',function(event){/ *。 .. * /},false)

The situation on mobile browsers is much better and is arguably the main target for this API. All major mobile browsers (Safari on iOS, Chrome/Opera/Firefox on Android) do support this event in its un-prefixed form i.e. window.addEventListener('deviceorientation', function(event) { /* ... */ }, false).

这篇关于Firefox中的“deviceorientation”?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆