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

取得窗口大小 兼容所有瀏覽器的js代碼

 更新時(shí)間:2011年08月09日 20:05:40   作者:  
我們首先把window.innerWidth和window.innerHeight的值分別付給了pageWidth和pageHeight。
取得窗口大小的代碼:
復(fù)制代碼 代碼如下:

var pageWidth = window.innerWidth,
var pageHeight = window.innerHeight;
if(typeof pageWidth != "number"){
if(document.compatMode == "number"){
pageWidth = document.documentElement.clientWidth;
pageHeight = document.documentElement.clientHeight;
}else{
pageWidth = document.body.clientWidth;
pageHeight = document.body.clientHeight;
}
}

我們首先把window.innerWidth和window.innerHeight的值分別付給了pageWidth和pageHeight。然后檢查pageWidth中保存的是不是一個(gè)數(shù)值;如果不是,則通過(guò)document.compatMode來(lái)確定頁(yè)面是否處于標(biāo)準(zhǔn)模式。如果是,則分別使用document.documentElement.clientWidth和document.documentElement.clientHeight的值。否則,就使用document.body.clientWidth和document.body.clientHeight的值。
取得窗口位置的代碼:
復(fù)制代碼 代碼如下:

var leftPos = (typeof window.screenLeft == "number") ? window.screenLeft : window.screenX;
var topPos = (typeof window.screenTop == "number") ? window.screenTop : window.screenY;
 
這兩個(gè)例子目的是取得窗口左邊和上邊的位置,首先運(yùn)用二元操作符判斷screenLeft屬性和screenTops屬性是否存在,如果存在(在IE、Safari、Opera和Chrome中),則取這兩個(gè)屬性的值。如果不存在(在Firefox中),則取screenX和screenY的值。

相關(guān)文章

最新評(píng)論