JavaScript获得页面区域大小的代码

时间:2009年06月18日作者:愚人码头查看次数:3,860 views评论次数:1

原文地址:http://andrewdupont.net/2006/09/09/viewport-dimensions-in-javascript/

一个JavaScript获得页面区域大小的代码,兼容性很好!


 var Client = {
      viewportWidth: function() {
        return self.innerWidth || (document.documentElement.clientWidth || document.body.clientWidth);
      },
 
      viewportHeight: function() {
        return self.innerHeight || (document.documentElement.clientHeight || document.body.clientHeight);
      },
 
      viewportSize: function() {
        return { width: this.viewportWidth(), height: this.viewportHeight() };
      }
     };

使用:Client.viewportHeight();

声明: 本文采用 BY-NC-SA 协议进行授权 | WEB前端开发
转载请注明转自《JavaScript获得页面区域大小的代码

如果你读了我的文章,觉得有帮助: 说明
标签:分类:JS
1条评论
  1. 蛋王留言于:2009年07月01日13:28

    这个挺实用,拿走,呵呵。

    [回复]

发表评论

*

*