您的位置:首页 > Web前端 > JavaScript

JS----Device.js 检测设备平台,操作系统的javascript

2015-06-15 12:45 671 查看
支持的设备有:

iOS: iPhone, iPod, iPad

Android: Phones & Tablets

Blackberry: Phones & Tablets

Windows: Phones & Tablets

Firefox OS: Phones & Tablets

使用:在head载入:<script src="device.js"></script>

它会自动在 <html> 标签添加一些设备平台,操作系统,方向相关的 CSS class,这样就能让你针对不同设备撰写不同的 CSS,并且还提供一些 Javascript 函数来判断设备

<html class="ios iphone mobile portrait">


生成的对比CSS Class:
		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		windows tablet
		Firefox OS Phone	fxos mobile
		Firefox OS Tablet	fxos tablet
		Desktop	desktop
		
	Orientation	CSS Classes
		Landscape	landscape
		Portrait	portrait



Javascript 函数

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()


Test:

<script src="style/js/device.js"></script>
<script>
alert(device.mobile())  //返回true, false,来判断设备
</script>


下载 Device.js
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: