@al01/detectdevice 设备检测库演示

注意:此演示展示了如何使用 @al01/detectdevice 库检测当前设备信息。 该库可以识别设备类型(手机、平板、桌面)、触摸支持、屏幕尺寸和操作系统等信息。

该项目仅适用于浏览器环境。

设备检测结果

正在检测设备信息...

使用方法

要在您的项目中使用此库,请按照以下步骤操作:

1. 通过 CDN 引入(浏览器环境)

<!-- 引入库文件 -->
<script src="https://cdn.jsdelivr.net/npm/@al01/detectdevice@latest/dist/index.browser.js"></script>
<script>
  // 直接调用 detectDevice 函数
  const device = detectDevice();
  console.log(device);
</script>

2. 通过 NPM 安装(Node.js 或模块化环境)

// 安装
npm install @al01/detectdevice

// 在项目中使用
import { detectDevice } from '@al01/detectdevice';

const device = detectDevice();
console.log(device);

返回的设备信息结构

{
  type: 'mobile' | 'tablet' | 'desktop', // 设备类型
  isMobile: boolean, // 是否为手机
  isTablet: boolean, // 是否为平板
  isDesktop: boolean, // 是否为桌面设备
  isTouch: boolean, // 是否支持触摸
  isSmallScreen: boolean, // 是否为小屏幕设备
  platform: 'ios' | 'android' | 'windows' | 'macos' | 'linux' | 'unknown' // 操作系统
}

GitHub 仓库

查看源码和更多文档:https://github.com/al01cn/detectdevice

Gitee 仓库

查看源码和更多文档:https://gitee.com/al01/detectdevice