javascript 得到当前页面可视高度和宽度
2009-09-19 13:24
435 查看
function getHeight(){
var yScroll;
if (window.innerHeight && window.scrollMaxY) {
yScroll = window.innerHeight + window.scrollMaxY;
} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
yScroll = document.body.scrollHeight;
} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
yScroll = document.body.offsetHeight;
}
var windowHeight;
if (self.innerHeight) { // all except Explorer
windowHeight = self.innerHeight;
} else if (document.documentElement && document.documentElement.clientHeight) {
// Explorer 6 Strict Mode
windowHeight = document.documentElement.clientHeight;
} else if (document.body) { // other Explorers
windowHeight = document.body.clientHeight;
}
// for small pages with total height less then height of the viewport
if(yScroll < windowHeight){
pageHeight = windowHeight;
} else {
pageHeight = yScroll;
}
return pageHeight;
}
function getWidth(){
var xScroll
if (window.innerHeight && window.scrollMaxY) {
xScroll = document.body.scrollWidth;
} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
xScroll = document.body.scrollWidth;
} else {
xScroll = document.body.offsetWidth;
}
var windowWidth
if (self.innerHeight) { // all except Explorer
windowWidth = self.innerWidth;
} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
windowWidth = document.documentElement.clientWidth;
} else if (document.body) { // other Explorers
windowWidth = document.body.clientWidth;
}
if(xScroll < windowWidth){
pageWidth = windowWidth;
} else {
pageWidth = xScroll;
}
return pageWidth;
}
var yScroll;
if (window.innerHeight && window.scrollMaxY) {
yScroll = window.innerHeight + window.scrollMaxY;
} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
yScroll = document.body.scrollHeight;
} else { // Explorer Mac...would also work in Explorer 6 Strict, Mozilla and Safari
yScroll = document.body.offsetHeight;
}
var windowHeight;
if (self.innerHeight) { // all except Explorer
windowHeight = self.innerHeight;
} else if (document.documentElement && document.documentElement.clientHeight) {
// Explorer 6 Strict Mode
windowHeight = document.documentElement.clientHeight;
} else if (document.body) { // other Explorers
windowHeight = document.body.clientHeight;
}
// for small pages with total height less then height of the viewport
if(yScroll < windowHeight){
pageHeight = windowHeight;
} else {
pageHeight = yScroll;
}
return pageHeight;
}
function getWidth(){
var xScroll
if (window.innerHeight && window.scrollMaxY) {
xScroll = document.body.scrollWidth;
} else if (document.body.scrollHeight > document.body.offsetHeight){ // all but Explorer Mac
xScroll = document.body.scrollWidth;
} else {
xScroll = document.body.offsetWidth;
}
var windowWidth
if (self.innerHeight) { // all except Explorer
windowWidth = self.innerWidth;
} else if (document.documentElement && document.documentElement.clientHeight) { // Explorer 6 Strict Mode
windowWidth = document.documentElement.clientWidth;
} else if (document.body) { // other Explorers
windowWidth = document.body.clientWidth;
}
if(xScroll < windowWidth){
pageWidth = windowWidth;
} else {
pageWidth = xScroll;
}
return pageWidth;
}
相关文章推荐
- javascript得到当前页面可视高度和宽度
- javascript 获取浏览器高度宽度 页面可视窗体高度宽度
- 得到当前页面高度和宽度的两个函数
- 在javascript中,我怎么得到下拉条顶端与当前可视的顶端高度的距离,不是和网页顶端的距离
- 网页javascript获得当前页面或窗口的各个宽度高度
- 在网页中通过javascript获得当前页面或窗口的各个宽度高度
- jquery 得到当前页面高度和宽度的两个函数
- jquery 得到当前页面高度和宽度
- jquery 得到当前页面高度和宽度的两个函数
- Javascript 获得页面的宽度和高度等!
- javascript 获取滚动条高度+常用js页面宽度与高度
- javascript 获取滚动条高度+常用js页面宽度与高度(转)
- javascript获取页面宽度高度及屏幕分辨率
- javascript 页面高度宽度等
- 获取当前页面的宽度和高度
- Javascript页面宽度高度
- javascript 获取滚动条高度+常用js页面宽度与高度
- [javascript] js 获取页面可视区高度和滚动条高度
- javascript获取页面的高度和宽度值
- JavaScript获取页面宽度高度大全