亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

三種檢測iPhone/iPad設(shè)備方向的方法

 更新時間:2014年04月23日 15:37:31   作者:  
這篇文章主要介紹了檢測iPhone/iPad設(shè)備方向的三種方法,需要的朋友可以參考下
使用meta tag "viewport"

viewport標(biāo)簽包含如下屬性:

 

為了能自動探測并適配到屏幕寬度,應(yīng)該使用device-with而不是設(shè)定一個固定值,另外為了避免用戶縮放導(dǎo)致界面超出屏幕,需要設(shè)置maximum-scale,
復(fù)制代碼 代碼如下:

<meta name="viewport" content="width=device-width, maximum-scale=1.0" />

使用javascript腳本

下面的腳本通過檢測屏幕寬度來檢測方向并調(diào)整方向:
復(fù)制代碼 代碼如下:

<script type="text/javascript">
var updateLayout = function() {
if (window.innerWidth != currentWidth) {
currentWidth = window.innerWidth;
var orient = (currentWidth == 320) ? "profile" : "landscape";
document.body.setAttribute("orient", orient);
window.scrollTo(0, 1);
}
};

iPhone.DomLoad(updateLayout);
setInterval(updateLayout, 400);
</script>

上述腳本可放在head部分

使用CSS

使用CSS的media query:
復(fù)制代碼 代碼如下:

<link rel="stylesheet" media="all and (orientation:portrait)" href="portrait.css">
<link rel="stylesheet" media="all and (orientation:landscape)" href="landscape.css">

相關(guān)文章

最新評論