http://segmentfault.com/a/1190000000373735
Device.js is a platform, operating system and direction JavaScript library that allows you to detect devices, and it automatically adds some device platforms, operating systems, and orientation-related CSS classes to your tags, so you can write different CSS for different devices. Some Javascript functions are also provided to determine the device.
Device.js via OS (such as IOS, Android, BlackBerry, Windows,firefox OX), direction (horizontal screen or vertical screen), type (tablet or mobile device), such as the following in the CSS class added on IPhone browsing:
Supported devices
- Ios:iphone, IPod, IPad
- Android:phones & Tablets
- Blackberry:phones & Tablets
- Windows:phones & Tablets
- Firefox Os:phones & Tablets
How to useDevice.js is very simple to use, just load the relevant JS library in the head of the page:
<script src="device.js"></script>
Generated CSS Class:
Device |
CSS Classes |
iPad | Td>ios ipad tablet
iPhone |
ios iPhone mobile |
iPod |
iOS ipod mobile |
android Phone |
android mobile |
Android tablet |
Android tablet |
BlackBerry Phone |
BlackBerry Mobile |
BlackBerry tablet |
BlackBerry tablet |
windows Phone |
Windows Mobile |
Windows tablet |
Windows tablet |
Firefox OS Phone |
fxos Mobile |
Firefox OS tablet |
fxos tablet |
Desktop |
desktop |
Orientation |
CSS Classes |
Landscape |
Landscape |
Portrait |
Portrait |
Related Javascript functions
Device |
JavaScript Method |
Mobile |
Device.mobile () |
Tablet |
Device.tablet () |
Ios |
Device.ios () |
Ipad |
Device.ipad () |
Iphone |
Device.iphone () |
Ipod |
Device.ipod () |
Android |
Device.android () |
Android Phone |
Device.androidphone () |
Android Tablet |
Device.androidtablet () |
BlackBerry |
Device.blackberry () |
BlackBerry Phone |
Device.blackberryphone () |
BlackBerry Tablet |
Device.blackberrytablet () |
Windows |
Device.windows () |
Windows Phone |
Device.windowsphone () |
Windows Tablet |
Device.windowstablet () |
Firefox OS |
Device.fxos () |
Firefox OS Phone |
Device.fxosphone () |
Firefox OS Tablet |
Device.fxostablet () |
Orientation |
JavaScript Method |
Landscape |
Device.landscape () |
Portrait |
Device.portrait () |
Project home: Device.js
Https://github.com/matthewhudson/device.js
device.js--detection device platform, operating system JavaScript library