首页 > 其他 > 详细

获取浏览器高度

时间:2016-06-22 02:04:37      阅读:255      评论:0      收藏:0      [点我收藏+]

获取浏览器的高度

(1)

获取浏览器可视区域的高度

$(window).height();
//Cross browser gets the size of Visual area window,Have nothing to do with scroll bars
/***
 * 仅获取可视区域的大小
 */
var getInner=(function() {
    // alert(typeof window.innerWidth !== ‘undefined‘);
    if (typeof window.innerWidth !== ‘undefined‘) {//Notice:‘undefined‘ is right
        return function(){
            return {
                width : window.innerWidth,
                height : window.innerHeight
            }
        }
    } else {
        return function(){
            return {
                width : document.documentElement.clientWidth,
                height : document.documentElement.clientHeight
            }
        }
    }
})();

?

(2)

获取整个文档的高度

$(document).height();
$(document.body).outerHeight(true);
//Cross browser gets the position of scroll
/***
 *
 * @returns {{top: number, left: number, height: 整个文档的高度,包括看不到的部分}}
 */
com.whuang.hsj.getScroll=function(){
    return {
        top:document.documentElement.scrollTop || document.body.scrollTop,
        left:document.documentElement.scrollLeft || document.body.scrollLeft,
        //等价于 $(document).height()
        height:document.documentElement.scrollHeight ||document.body.scrollHeight
    };
};

?

(3)com.whuang.hsj.getScroll()中的height


bubuko.com,布布扣
?$ (‘body’).height() 只表示body的高度,不包括body的margin

获取浏览器高度

原文:http://hw1287789687.iteye.com/blog/2305709

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!