JavaScript。监听 iPhone 震动事件?

发布于 2024-08-20 15:30:46 字数 121 浏览 3 评论 0原文

是否可以使用 JavaScript 监听 iPhone(或任何带有加速计的手机)震动事件?你知道,就像摇动 iPhone 来随机播放 iTunes 中的下一首歌曲一样,当 iPhone 摇动时,我想在我的网站上调用 JS 函数。

Is it possible to listen for an iPhone (or any mobile phone with accelerometer) shake event with JavaScript? You know like shaking the iPhone to shuffle the next song in iTunes I want to call a JS function on my website when the iPhone got shaken.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

你穿错了嫁妆 2024-08-27 15:30:46

在最新的 iOS 更新 (4.2) 中,现在可以通过 Javascript 访问加速度计。

请参阅:http://www.mobilexweb.com/blog/safari-ios -加速计-websockets-html5

In the latest iOS update (4.2) the accelorometer is now accessible from Javascript.

See: http://www.mobilexweb.com/blog/safari-ios-accelerometer-websockets-html5

染火枫林 2024-08-27 15:30:46

如果有人正在寻找的话,这里有一个使用加速度计进行震动检测的优雅实现:

https://github.com/alexgibson/shake.js

Here's an elegant implementation of shake detection using the accelerometer if anyone is looking for it:

https://github.com/alexgibson/shake.js

回忆躺在深渊里 2024-08-27 15:30:46

我刚刚在我的网络应用程序中实现了上述内容,该应用程序现在只有在设备震动发生后才会出现在页面上的控件。非常容易实现并且描述清晰。

https://github.com/alexgibson/shake.js

还值得注意的是,iOS模拟器的摇动手势不会触发该事件,但真正的设备摇动会触发该事件。

I just implemented the above in my web app which now has controls that appear on the page only after a device shake occurs. Very easy to implement and cleanly described.

https://github.com/alexgibson/shake.js

It is also worth noting that the iOS simulator's shake gesture doesn't trigger the event but a genuine device shake does.

我不是你的备胎 2024-08-27 15:30:46

不是作为一个直接的网络应用程序,不。如果您将 Web 应用程序封装在 PhoneGap 中,它会向在其中运行的网站公开加速计和其他仅限应用程序的功能,但缺点是人们必须实际下载您的应用程序 - 他们不能只浏览 Safari 中的网站。

Not as a straight web app, no. If you wrap your web app in PhoneGap, it exposes accelerometer and other app-only features to the site running within it, but the downside is that people have to actually download your app - they can't just browse to a site in Safari.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文