Device.js——检测装备平台、操作系统的Javascript 库

Device.js 是一个能够让你检测装备的平台,操作系统和方向 JavaScript 库,它会自动在 <html> 标签增加一些装备平台,操作系统,方向相干的 CSS class,如许就能让你针对差别装备撰写差别的 CSS,而且还供应一些 Javascript 函数来推断装备。

《Device.js——检测装备平台、操作系统的Javascript 库》

Device.js 经由过程操作系统(比方 iOS,安卓,黑莓,Windows,Firefox OX),方向(横屏或许竖屏),范例(平板或许挪动装备),如下面在 iPhone 上的阅读的时刻在 <html> 增加的 CSS Class:

《Device.js——检测装备平台、操作系统的Javascript 库》

支撑的装备

  • iOS: iPhone, iPod, iPad
  • Android: Phones & Tablets
  • Blackberry: Phones & Tablets
  • Windows: Phones & Tablets
  • Firefox OS: Phones & Tablets

怎样运用

Device.js 运用异常简朴,只需要在页面的 head 载入相干的 JS 库即可:

<script src="device.js"></script>

天生的 CSS Class:

DeviceCSS Classes
iPadios ipad tablet
iPhoneios iphone mobile
iPodios ipod mobile
Android Phoneandroid mobile
Android Tabletandroid tablet
BlackBerry Phoneblackberry mobile
BlackBerry Tabletblackberry tablet
Windows Phonewindows mobile
Windows Tabletwindows tablet
Firefox OS Phonefxos mobile
Firefox OS Tabletfxos tablet
Desktopdesktop
OrientationCSS Classes
Landscapelandscape
Portraitportrait

相干的 Javascript 函数

DeviceJavaScript Method
Mobiledevice.mobile()
Tabletdevice.tablet()
iOSdevice.ios()
iPaddevice.ipad()
iPhonedevice.iphone()
iPoddevice.ipod()
Androiddevice.android()
Android Phonedevice.androidPhone()
Android Tabletdevice.androidTablet()
BlackBerrydevice.blackberry()
BlackBerry Phonedevice.blackberryPhone()
BlackBerry Tabletdevice.blackberryTablet()
Windowsdevice.windows()
Windows Phonedevice.windowsPhone()
Windows Tabletdevice.windowsTablet()
Firefox OSdevice.fxos()
Firefox OS Phonedevice.fxosPhone()
Firefox OS Tabletdevice.fxosTablet()
OrientationJavaScript Method
Landscapedevice.landscape()
Portraitdevice.portrait()

项目主页:Device.js

via wpjam

    原文作者:weakish
    原文地址: https://segmentfault.com/a/1190000000373735
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞