码迷,mamicode.com
首页 > 编程语言 > 详细

getViewport() JavaScript获取浏览器视口的尺寸

时间:2015-01-25 18:12:57      阅读:370      评论:0      收藏:0      [点我收藏+]

标签:

function getViewport() {
    var w = window.innerWidth ? window.innerWidth :
                document.documentElement && document.documentElement.clientWidth ? document.documentElement.clientWidth :
                    document.body.offsetWidth;

    var h = window.innerHeight ? window.innerHeight :
                document.documentElement && document.documentElement.clientHeight ? document.documentElement.clientHeight :
                    document.body.offsetHeight;

    return {
        width : w,
        height: h
    };
};

 

getViewport() JavaScript获取浏览器视口的尺寸

标签:

原文地址:http://www.cnblogs.com/happyfreelife/p/4248502.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!