Device.js makes it easy for you to write Conditional CSS and JavaScript based on device operating system (iOS, Android, Blackberry), orientation (Portrait vs. Landscape), and type (Tablet vs. Mobile).
Device.js inserts CSS classes into the <html>
element.
Just include the script. The script then updates the <html>
section with the appropriate classes based on the device's characteristics.
<script src="device.js"></script>
The following tables map which CSS classes are added based on device and orientation.
Device | CSS Classes |
---|---|
iPad | 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 | (no support) |
Desktop | desktop |
Orientation | CSS Classes |
---|---|
Landscape | landscape |
Portrait | portrait |
Device.js also includes support for conditional JavaScript, allowing you to write checks on the following device characteristics:
Device | JavaScript Method |
---|---|
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 Phone | device.windowsPhone() |
Windows Tablet | (no support) |
Orientation | JavaScript Method |
---|---|
Landscape | device.landscape() |
Portrait | device.portrait() |
- Add UserAgent sniffing for edge cases.
- Add fallback in case "orientation" event doesn't exist.
- iOS: iPhone, iPod, iPad
- Android: Phones & Tablets
- Blackberry: Phones & Tablets
- Windows Phone (no Windows Tablet support yet)
All comments in how to improve this library are very welcome. Feel free post suggestions to the Issue tracker, or even better, fork the repository to implement your own ideas and submit a pull request.
Unless attributed otherwise, everything is under the MIT License (see LICENSE for more info).