準(zhǔn)確獲得頁(yè)面、窗口高度及寬度的JS
更新時(shí)間:2006年11月26日 00:00:00 作者:
function getPageSize(){
var xScroll, yScroll;
if (window.innerHeight && window.scrollMaxY) {
xScroll = document.body.scrollWidth;
yScroll = window.innerHeight + window.scrollMaxY;
} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
xScroll = document.body.scrollWidth;
yScroll = document.body.scrollHeight;
} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
xScroll = document.body.offsetWidth;
yScroll = document.body.offsetHeight;
}
var windowWidth, windowHeight;
if (self.innerHeight) { // all except Explorer
windowWidth = self.innerWidth;
windowHeight = self.innerHeight;
} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
windowWidth = document.documentElement.clientWidth;
windowHeight = document.documentElement.clientHeight;
} else if (document.body) { // other Explorers
windowWidth = document.body.clientWidth;
windowHeight = document.body.clientHeight;
}
// for small pages with total height less then height of the viewport
if(yScroll < windowHeight){
pageHeight = windowHeight;
} else {
pageHeight = yScroll;
}
// for small pages with total width less then width of the viewport
if(xScroll < windowWidth){
pageWidth = windowWidth;
} else {
pageWidth = xScroll;
}
arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
return arrayPageSize;
}
有幸找到了你的這個(gè)東東,幫我解決了問(wèn)題,不過(guò)仔細(xì)看了下,好象大大的有點(diǎn)問(wèn)題,參數(shù)值和名稱上看好象有點(diǎn)對(duì)不上號(hào)哦.
// for small pages with total height less then height of the viewport
if(yScroll < windowHeight){
pageHeight = yScroll;
} else {
pageHeight = windowHeight;
}
// for small pages with total width less then width of the viewport
if(xScroll < windowWidth){
pageWidth = xScroll;
} else {
pageWidth = windowWidth;
}
var xScroll, yScroll;
if (window.innerHeight && window.scrollMaxY) {
xScroll = document.body.scrollWidth;
yScroll = window.innerHeight + window.scrollMaxY;
} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
xScroll = document.body.scrollWidth;
yScroll = document.body.scrollHeight;
} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
xScroll = document.body.offsetWidth;
yScroll = document.body.offsetHeight;
}
var windowWidth, windowHeight;
if (self.innerHeight) { // all except Explorer
windowWidth = self.innerWidth;
windowHeight = self.innerHeight;
} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
windowWidth = document.documentElement.clientWidth;
windowHeight = document.documentElement.clientHeight;
} else if (document.body) { // other Explorers
windowWidth = document.body.clientWidth;
windowHeight = document.body.clientHeight;
}
// for small pages with total height less then height of the viewport
if(yScroll < windowHeight){
pageHeight = windowHeight;
} else {
pageHeight = yScroll;
}
// for small pages with total width less then width of the viewport
if(xScroll < windowWidth){
pageWidth = windowWidth;
} else {
pageWidth = xScroll;
}
arrayPageSize = new Array(pageWidth,pageHeight,windowWidth,windowHeight)
return arrayPageSize;
}
有幸找到了你的這個(gè)東東,幫我解決了問(wèn)題,不過(guò)仔細(xì)看了下,好象大大的有點(diǎn)問(wèn)題,參數(shù)值和名稱上看好象有點(diǎn)對(duì)不上號(hào)哦.
// for small pages with total height less then height of the viewport
if(yScroll < windowHeight){
pageHeight = yScroll;
} else {
pageHeight = windowHeight;
}
// for small pages with total width less then width of the viewport
if(xScroll < windowWidth){
pageWidth = xScroll;
} else {
pageWidth = windowWidth;
}
您可能感興趣的文章:
- jquery 得到當(dāng)前頁(yè)面高度和寬度的兩個(gè)函數(shù)
- 用js來(lái)定義瀏覽器中一個(gè)左右浮動(dòng)元素相對(duì)于頁(yè)面主體寬度的位置的函數(shù)
- js獲得頁(yè)面的高度和寬度的方法
- js 獲取頁(yè)面高度和寬度兼容 ie firefox chrome等
- jquery實(shí)現(xiàn)在頁(yè)面加載完畢后獲取圖片高度或?qū)挾?/a>
- jquery實(shí)現(xiàn)類似EasyUI的頁(yè)面布局可改變左右的寬度
- js獲取input長(zhǎng)度并根據(jù)頁(yè)面寬度設(shè)置其大小及居中對(duì)齊
- 手機(jī)端頁(yè)面rem寬度自適應(yīng)腳本
- jQuery獲取頁(yè)面及個(gè)元素高度、寬度的總結(jié)——超實(shí)用
- 手機(jī)屏幕尺寸測(cè)試——手機(jī)的實(shí)際顯示頁(yè)面的寬度
相關(guān)文章
echart簡(jiǎn)介_(kāi)動(dòng)力節(jié)點(diǎn)Java學(xué)院整理
這篇文章主要介紹了echart簡(jiǎn)介,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧2017-08-08
javaScript中push函數(shù)用法實(shí)例分析
這篇文章主要介紹了javaScript中push函數(shù)用法,較為詳細(xì)的分析了javascript中push函數(shù)的功能、定義及使用技巧,需要的朋友可以參考下2015-06-06
如何高效率去掉js數(shù)組中的重復(fù)項(xiàng)
如何高效率去掉js數(shù)組中的重復(fù)項(xiàng)呢?下面小編就為大家?guī)?lái)一篇高效率去掉js數(shù)組中重復(fù)項(xiàng)的實(shí)現(xiàn)方法。希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2016-04-04
javascript使用數(shù)組的push方法完成快速排序
排序的方法有很多,本節(jié)為大家介紹的是使用數(shù)組的push方法完成快速排序,當(dāng)然你也可以舉一反三2014-09-09
js中各種時(shí)間日期格式之間的轉(zhuǎn)換代碼示例
這篇文章主要介紹了js中各種時(shí)間日期格式之間轉(zhuǎn)換的相關(guān)資料,還有獲取今天的年月日和計(jì)算兩個(gè)日期之間的相差天數(shù)的方法,文中通過(guò)代碼介紹的非常詳細(xì),需要的朋友可以參考下2025-03-03
p5.js實(shí)現(xiàn)動(dòng)態(tài)圖形臨摹
這篇文章主要為大家詳細(xì)介紹了p5.js實(shí)現(xiàn)動(dòng)態(tài)圖形臨摹,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2019-10-10

