準(zhǔn)確獲得頁面、窗口高度及寬度的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è)東東,幫我解決了問題,不過仔細(xì)看了下,好象大大的有點(diǎ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è)東東,幫我解決了問題,不過仔細(xì)看了下,好象大大的有點(diǎ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)前頁面高度和寬度的兩個(gè)函數(shù)
- 用js來定義瀏覽器中一個(gè)左右浮動(dòng)元素相對(duì)于頁面主體寬度的位置的函數(shù)
- js獲得頁面的高度和寬度的方法
- js 獲取頁面高度和寬度兼容 ie firefox chrome等
- jquery實(shí)現(xiàn)在頁面加載完畢后獲取圖片高度或?qū)挾?/a>
- jquery實(shí)現(xiàn)類似EasyUI的頁面布局可改變左右的寬度
- js獲取input長度并根據(jù)頁面寬度設(shè)置其大小及居中對(duì)齊
- 手機(jī)端頁面rem寬度自適應(yīng)腳本
- jQuery獲取頁面及個(gè)元素高度、寬度的總結(jié)——超實(shí)用
- 手機(jī)屏幕尺寸測(cè)試——手機(jī)的實(shí)際顯示頁面的寬度
相關(guān)文章
javascript 判斷一個(gè)對(duì)象為數(shù)組的方法
這篇文章主要介紹了javascript 判斷一個(gè)對(duì)象為數(shù)組的方法的相關(guān)資料,需要的朋友可以參考下2017-05-05詳細(xì)聊聊TypeScript中any unknown never和void的區(qū)別
這篇文章主要給大家聊聊TypeScript 中 any、unknown、never 和 void 有什么區(qū)別,文中有詳細(xì)的代碼實(shí)例講解,具有一定的參考價(jià)值,需要的朋友可以參考下2023-07-07微信小程序?qū)崿F(xiàn)點(diǎn)擊卡片 翻轉(zhuǎn)效果
這篇文章主要介紹了微信小程序?qū)崿F(xiàn)點(diǎn)擊卡片 翻轉(zhuǎn)效果本文通過實(shí)例代碼給大家介紹的非常詳細(xì),具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2019-09-09Handtrack.js庫實(shí)現(xiàn)實(shí)時(shí)監(jiān)測(cè)手部運(yùn)動(dòng)(推薦)
這篇文章主要介紹了實(shí)時(shí)監(jiān)測(cè)手部運(yùn)動(dòng)的 JS 庫,可以實(shí)現(xiàn)很多有趣功能,本文給大家介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2021-02-02