最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

js/jquery獲取瀏覽器窗口可視區(qū)域高度和寬度以及滾動(dòng)條高度實(shí)現(xiàn)代碼

 更新時(shí)間:2012年12月17日 17:09:59   作者:  
在js使用過(guò)程中可能會(huì)根據(jù)要求獲取瀏覽器窗口的可視區(qū)域高度和寬度,滾動(dòng)條高度,于是本人搜集整理下,拿出來(lái)和大家分享,希望可以幫助你們
獲取瀏覽器窗口的可視區(qū)域高度和寬度,滾動(dòng)條高度有需要的朋友可參考一下。
IE中,瀏覽器顯示窗口大小只能以下獲?。?nbsp;代碼如下復(fù)制代碼
復(fù)制代碼 代碼如下:

document.body.offsetWidth
document.body.offsetHeight

在聲明了DOCTYPE的瀏覽器中,可以用以下來(lái)獲取瀏覽器顯示窗口大?。?nbsp;代碼如下復(fù)制代碼
復(fù)制代碼 代碼如下:

document.documentElement.clientWidth
document.documentElement.clientHeight

IE,F(xiàn)F,Safari皆支持該方法,opera雖支持該屬性,但是返回的是頁(yè)面尺寸;
同時(shí),除了IE以外的所有瀏覽器都將此信息保存在window對(duì)象中,可以用以下獲?。?nbsp;代碼如下復(fù)制代碼
復(fù)制代碼 代碼如下:

window.innerWidth
window.innerHeight

整個(gè)網(wǎng)頁(yè)尺寸一般獲得方法 代碼如下復(fù)制代碼
復(fù)制代碼 代碼如下:

document.body.scrollWidth
document.body.scrollHeight

屏幕分辨率高度一般獲得方法 代碼如下復(fù)制代碼
復(fù)制代碼 代碼如下:

window.screen.height
window.screen.width

總結(jié)一下實(shí)例
復(fù)制代碼 代碼如下:

function getViewSizeWithoutScrollbar(){//不包含滾動(dòng)條
return {
width : document.documentElement.clientWidth,
height: document.documentElement.clientHeight
}
}
function getViewSizeWithScrollbar(){//包含滾動(dòng)條
if(window.innerWidth){
return {
width : window.innerWidth,
height: window.innerHeight
}
}else if(document.documentElement.offsetWidth == document.documentElement.clientWidth){
return {
width : document.documentElement.offsetWidth,
height: document.documentElement.offsetHeight
}
}else{
return {
width : document.documentElement.clientWidth + getScrollWith(),
height: document.documentElement.clientHeight + getScrollWith()
}
}
}

IE,F(xiàn)ireFox 差異如下:
IE6.0、FF1.06+: 
復(fù)制代碼 代碼如下:

clientWidth = width + padding
clientHeight = height + padding
offsetWidth = width + padding + border
offsetHeight = height + padding + border
IE5.0/5.5:
clientWidth = width - border
clientHeight = height - border
offsetWidth = width
offsetHeight = height

另附個(gè)人最常用的獲取整頁(yè)寬高的方法(需要jquery框架) 代碼如下復(fù)制代碼
復(fù)制代碼 代碼如下:

$(document).width() < $('body').width() ? $(document).width() : $('body').width();
$(document).height() < $('body').height() ? $(document).height() : $('body').height();

alert($(window).height()); //瀏覽器時(shí)下窗口可視區(qū)域高度
alert($(document).height()); //瀏覽器時(shí)下窗口文檔的高度
alert($(document.body).height());//瀏覽器時(shí)下窗口文檔body的高度
alert($(document.body).outerHeight(true));//瀏覽器時(shí)下窗口文檔body的總高度 包括border padding margin
alert($(window).width()); //瀏覽器時(shí)下窗口可視區(qū)域?qū)挾?BR>alert($(document).width());//瀏覽器時(shí)下窗口文檔對(duì)于象寬度
alert($(document.body).width());//瀏覽器時(shí)下窗口文檔body的高度
alert($(document.body).outerWidth(true));//瀏覽器時(shí)下窗口文檔body的總寬度 包括border padding margin

alert($(document).scrollTop()); //獲取滾動(dòng)條到頂部的垂直高度
alert($(document).scrollLeft()); //獲取滾動(dòng)條到左邊的垂直寬度

相關(guān)文章

最新評(píng)論

温泉县| 任丘市| 阿拉善右旗| 青阳县| 台东县| 泰顺县| 衡阳市| 蕉岭县| 修武县| 汉中市| 泰兴市| 万源市| 临清市| 昌都县| 安徽省| 论坛| 洪江市| 南城县| 中牟县| 吉隆县| 昆山市| 商河县| 上高县| 章丘市| 都昌县| 洪江市| 江西省| 郎溪县| 方正县| 新巴尔虎左旗| 轮台县| 苏尼特左旗| 蓝山县| 东乌珠穆沁旗| 民县| 海兴县| 北碚区| 星子县| 兴义市| 清徐县| 固始县|