javascript - 设备方向未按预期工作
问题描述
我正在使用 deviceorientation 侦听器尝试一些代码,但它没有像我预期的那样工作。我尝试了几种不同的方法(如下所示),并且在手动更改 Chrome 的调试器传感器时都可以正常工作,但是,我无法让它在任何移动设备上自动工作。
我将此站点用作参考和演示:
- https://www.audero.it/demo/device-orientation-api-demo.html
- https://code.tutsplus.com/tutorials/an-introduction-to-the-device-orientation-api--cms-21067
上面的演示在我的手机上运行良好,但是当我尝试在我正在处理的内容中实现相同的代码时,什么也没有发生。
export class AppComponent {
absolute: boolean = false;
alpha: number = 0;
beta: number = 0;
gamma: number = 0;
private orientation$ = fromEvent(window, 'deviceorientation');
constructor() { }
ngAfterViewInit() {
// Method 1
window.addEventListener('deviceorientation', (e) => console.log(e));
// Method 2
this.orientation$.subscribe((res: any) => console.log(res));
}
}
有什么我想念的想法吗?
解决方案
推荐阅读
- c# - C# Eventbrite 创建事件
- php - 邮件函数在 PHP 中给出错误返回
- nativescript - nativescript-angular:无法将下拉值设置为默认选择
- node.js - 在不重置数据库的情况下在 sequelize 中添加列
- sed - 用 sed 删除(或替换)带有斜线的单词
- apache-kafka - Kafka 连接器的 Presto 查询优化
- talend - 使用 MetaServlet API 从 Talend Administration Center 检索所有标签及其作业名称的列表
- python - SLinkedList 对象不可调用
- c++ - C++ OOP 分段错误
- azure - 将 Azure 连接传递到 Azure DevOps 管道中的控制台应用