设备

Framework7 附带设备检测库,其中包含有关设备和平台的有用信息。

它可以作为 Framework7 类的属性 (device) 和初始化的应用实例上的相同属性 (Framework7.device) 使用。app.device)访问:

// If we need it in place where we don't have access to app instance or before we init the app
if (Framework7.device.ios) {
  console.log('It is iOS device');
}


// After we init the app we can access it as app instance property
var app = new Framework7({ /*...*/ });
if (app.device.android) {
  console.log('It is android device');
}

getDevice

当我们在服务器端环境或使用 ES 模块时,我们需要使用getDeviceutil 而不是:

import { getDevice } from 'framework7';

const device = getDevice();

if (device.android) {
  console.log('It is android device');
}

如果我们在服务器端使用它,我们也可以传递userAgent对于如果我们知道它基于请求的情况:

import { getDevice } from 'framework7';

const device = getDevice({ userAgent: 'SOME_USER_AGENT' });

if (device.android) {
  console.log('It is android device');
}

方法与属性

属性
iostrue对于 iOS 设备
androidtrue对于 Android 设备
androidChrometrue对于 Android Chrome
desktoptrue对于桌面浏览器
iphonetrue对于 iPhone
ipodtrue对于 iPod
ipadtrue对于 iPad
cordovatrue当应用在 cordova 环境中运行时
capacitortrue当应用在 capacitor 环境中运行时
windowstrue对于桌面 Windows
macostrue对于桌面 macOS
ietrue对于 Internet Explorer 浏览器
edgetrue对于 MS Edge 浏览器
firefoxtrue对于 FireFox 浏览器
electrontrue当应用在 Electron 环境下运行时
nwjstrue当应用在 NW.js 环境下运行时
webViewtrue如果应用在 webView 中运行 - webapp 安装到主屏幕,适用于桌面 PWAs 安装到桌面
standalonewebView
os包含可ios, android, macos, windows
osVersion包含 OS 版本,例如11.2.0
pixelRatio设备像素比
方法
prefersColorScheme()返回首选用户系统配色方案。返回"light""dark"如果此功能受支持或undefined否则。此功能支持基于(prefers-color-scheme)media query 支持.

设备检测库在元素上添加了额外的类,这些类可以帮助您为不同的 OS 和平台应用不同的 CSS 样式。<html> element which can help you with different CSS styles for different OS and platforms.

换句话说,类按以下规则计算:

device-[os]
device-desktop
device-macos - if desktop macOS device
device-windows - if desktop windows device
device-pixel-ratio-[pixel ratio]
device-cordova - if app running under cordova