我确定我只是忽略了这个问题,但我似乎无法找到如何检查设备.
我想检查设备是手机,横向模式平板电脑,纵向模式平板电脑还是其他设备(计算机).
我有的是这个:
if (Ext.platform.isPhone) {
console.log("phone");
}
if (Ext.platform.isTablet) {
console.log("tablet");
}
var x = Ext.platform;
Run Code Online (Sandbox Code Playgroud)
但是平台是未定义的(可能是因为这是Sencha Touch 1的方式).
有谁知道我访问设备检查的正确位置?
gre*_*ott 18
Sencha环境检测通过简单的方法提供大范围的光谱.
而不是Ext.os.is.Tablet,您可以通过Ext.os.deviceType使生活更轻松,它将返回:
注意:也可以通过在网址中添加"?deviceType ="来捏造此值.
http://localhost/mypage.html?deviceType=Tablet
Run Code Online (Sandbox Code Playgroud)
Ext.os.name是返回的单例:
通过Ext.browser.name可以获得通常的浏览器检测功能.
我最近才遇到的东西,我喜欢的是功能检测 - 允许类似于Modernizr/YepNope的编码基于设备的能力.Ext.feature提供:
要在iOS上检测全屏/应用/主屏幕浏览器模式:
window.navigator.standalone == true
Run Code Online (Sandbox Code Playgroud)
Orientation Ext.device.Orientation和orientation changes:
Ext.device.Orientation.on({
scope: this,
orientationchange: function(e) {
console.log('Alpha: ', e.alpha);
console.log('Beta: ', e.beta);
console.log('Gamma: ', e.gamma);
}
});
Run Code Online (Sandbox Code Playgroud)
方向基于Viewport.我通常添加一个更可靠的监听器:
onOrientationChange: function(viewport, orientation, width, height) {
// test trigger and values
console.log('o:' + orientation + ' w:' + width + ' h:' + height);
if (width > height) {
orientation = 'landscape';
} else {
orientation = 'portrait';
}
// add handlers here...
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
11810 次 |
| 最近记录: |