Sencha Environment Detection 通过简单的方式提供大范围的频谱。
除了 Ext.os.is.Tablet,您可以通过 Ext.os.deviceType 让生活更轻松,这将返回:
注意:这个值也可以通过在 url 中添加“?deviceType=”来伪造。
http://localhost/mypage.html?deviceType=Tablet
Ext.os.name 是单例返回:
- iOS
- 安卓
- 网络操作系统
- 黑莓
- RIMTablet
- MacOS
- 窗口
- Linux
- 八达
- 其他
通过Ext.browser.name可以使用通常的浏览器检测功能。
我最近才遇到的东西,我喜欢的是特征检测 - 允许基于设备能力进行类似于 Modernizr / YepNope 的编码。 Ext.feature 提供:
- Ext.feature.has.Audio
- Ext.feature.has.Canvas
- Ext.feature.has.ClassList
- Ext.feature.has.CreateContextualFragment
- Ext.feature.has.Css3dTransforms
- Ext.feature.has.CssAnimations
- Ext.feature.has.CssTransforms
- Ext.feature.has.CssTransitions
- Ext.feature.has.DeviceMotion
- Ext.feature.has.Geolocation
- Ext.feature.has.History
- Ext.feature.has.Orientation
- Ext.feature.has.OrientationChange
- Ext.feature.has.Range
- Ext.feature.has.SqlDatabase
- Ext.feature.has.Svg
- Ext.feature.has.Touch
- Ext.feature.has.Video
- Ext.feature.has.Vml
- Ext.feature.has.WebSockets
在 iOS 上检测全屏/应用/主屏浏览器模式:
window.navigator.standalone == true
方向Ext.device.Orientation和方向变化:
Ext.device.Orientation.on({
scope: this,
orientationchange: function(e) {
console.log('Alpha: ', e.alpha);
console.log('Beta: ', e.beta);
console.log('Gamma: ', e.gamma);
}
});
方向基于视口。我通常会添加一个更可靠的监听器:
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...
}