准确获得页面、窗口高度及宽度的JS

 更新时间: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;
}
有幸找到了你的这个东东,帮我解决了问题,不过仔细看了下,好象大大的有点问题,参数值和名称上看好象有点对不上号哦. 
// 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; 
}

相关文章

  • echart简介_动力节点Java学院整理

    echart简介_动力节点Java学院整理

    这篇文章主要介绍了echart简介,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2017-08-08
  • js替换字符串的所有示例代码

    js替换字符串的所有示例代码

    本文为大家详细介绍下js如何替换字符串中所有,肯定包含了你所想要的,具体的实现思路及代码如下,感兴趣的朋友可以参考下哈,希望对大家有所帮助
    2013-07-07
  • Rxjs tap 操作符的使用场景示例

    Rxjs tap 操作符的使用场景示例

    这篇文章主要为大家介绍了Rxjs tap 操作符的使用场景示例详解,有需要的朋友可以借鉴参考下,希望能够有所帮助,祝大家多多进步,早日升职加薪
    2023-07-07
  • es6新特性之 class 基本用法解析

    es6新特性之 class 基本用法解析

    这篇文章主要介绍了es6新特性之 class 基本用法 ,非常不错,具有参考借鉴价值,需要的朋友可以参考下
    2018-05-05
  • javaScript中push函数用法实例分析

    javaScript中push函数用法实例分析

    这篇文章主要介绍了javaScript中push函数用法,较为详细的分析了javascript中push函数的功能、定义及使用技巧,需要的朋友可以参考下
    2015-06-06
  • 深入理解JavaScript柯里化的概念和原理

    深入理解JavaScript柯里化的概念和原理

    在JS编程中, 函数是一等公民, 具备了强大的灵活性和复用性,而柯里化作为一种高阶技术, 可以进一步提升函数的复用性和灵活性,在本篇博客中, 我们将深入探讨 JS 中柯里化的概念和原理, 并了解其在实际开发中的应用场景,需要的朋友可以参考下
    2023-06-06
  • 如何高效率去掉js数组中的重复项

    如何高效率去掉js数组中的重复项

    如何高效率去掉js数组中的重复项呢?下面小编就为大家带来一篇高效率去掉js数组中重复项的实现方法。希望对大家有所帮助。一起跟随小编过来看看吧
    2016-04-04
  • javascript使用数组的push方法完成快速排序

    javascript使用数组的push方法完成快速排序

    排序的方法有很多,本节为大家介绍的是使用数组的push方法完成快速排序,当然你也可以举一反三
    2014-09-09
  • js中各种时间日期格式之间的转换代码示例

    js中各种时间日期格式之间的转换代码示例

    这篇文章主要介绍了js中各种时间日期格式之间转换的相关资料,还有获取今天的年月日和计算两个日期之间的相差天数的方法,文中通过代码介绍的非常详细,需要的朋友可以参考下
    2025-03-03
  • p5.js实现动态图形临摹

    p5.js实现动态图形临摹

    这篇文章主要为大家详细介绍了p5.js实现动态图形临摹,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2019-10-10

最新评论