`
robinqu
  • 浏览: 88678 次
  • 性别: Icon_minigender_1
  • 来自: 武汉
社区版块
存档分类
最新评论

Javascript 窗口的几何关系和相关方法、属性

阅读更多
Window Geometry
窗口几何关系

引用
Screen coordinates describe the position of a browser window on the desktop; they are measured relative to the upper-left corner of the desktop.


Screen坐标系是描述浏览器窗口和桌面之间的几何关系的,其坐标是相对于桌面左上角的。

引用
Window coordinates describe a position within the web browser's viewport; they are measured relative to the upper-left corner of the viewport.


Window坐标系描述了浏览器页面可视区域的几何关系,其坐标是相对于可视区域的左上角。

引用
Document coordinates describe a position within an HTML document; they are measured relative to the upper-left corner of the document. When the document is longer or wider than the viewport (as web pages often are), document coordinates and window coordinates are not the same, and you'll need to take the position of the scrollbars into account when converting between these two coordinate systems.


Document坐标系描述了HTML元素与document文档的几何关系,其坐标是相对于document对象的左上角的。
当document足够长而产生滚动条,document坐标系和window坐标系就会产生差异,两个坐标系之间就要考虑转换的方法。

引用
For some reason, IE places these window geometry properties on the <body> of the HTML document. And, further confusing matters, IE 6, when displaying a document with a <!DOCTYPE> declaration, places the properties on the document.documentElement element instead of document.body.


IE在默认状态下将这些相关属性放在document.body下,但如果有<!DOCTYPE>声明,那么就会放在document.documentElement下。
浏览器window对象坐标大小可视区域大小滚动条document对象坐标大小
FFscreenX/YinnerWidth/HeightpageXOffset/YOffsetdocumentElement.scrollLeft/Top
IE with doctypescreenLeft/TopdocumentElement.clientWidthdocumentElement.scrollLeft/Top/HeightdocumentElement.scrollLeft/Top


以下是一个获取几何参数的函数

/**
 * Geometry.js: portable functions for querying window and document geometry
 *
 * This module defines functions for querying window and document geometry.
 *
 * getWindowX/Y( ): return the position of the window on the screen
 * getViewportWidth/Height( ): return the size of the browser viewport area
 * getDocumentWidth/Height( ): return the size of the document
 * getHorizontalScroll( ): return the position of the horizontal scrollbar
 * getVerticalScroll( ): return the position of the vertical scrollbar
 *
 * Note that there is no portable way to query the overall size of the
 * browser window, so there are no getWindowWidth/Height( ) functions.
 *
 * IMPORTANT: This module must be included in the <body> of a document
 *            instead of the <head> of the document.
 */
var Geometry = {};

if (window.screenLeft) { // IE and others
    Geometry.getWindowX = function( ) { return window.screenLeft; };
    Geometry.getWindowY = function( ) { return window.screenTop; };
}
else if (window.screenX) { // Firefox and others
    Geometry.getWindowX = function( ) { return window.screenX; };
    Geometry.getWindowY = function( ) { return window.screenY; };
}

if (window.innerWidth) { // All browsers but IE
    Geometry.getViewportWidth = function( ) { return window.innerWidth; };
    Geometry.getViewportHeight = function( ) { return window.innerHeight; };
    Geometry.getHorizontalScroll = function( ) { return window.pageXOffset; };
    Geometry.getVerticalScroll = function( ) { return window.pageYOffset; };
}
else if (document.documentElement && document.documentElement.clientWidth) {
    // These functions are for IE 6 when there is a DOCTYPE
    Geometry.getViewportWidth =
        function( ) { return document.documentElement.clientWidth; };
    Geometry.getViewportHeight =
        function( ) { return document.documentElement.clientHeight; };
    Geometry.getHorizontalScroll =
        function( ) { return document.documentElement.scrollLeft; };
    Geometry.getVerticalScroll =
        function( ) { return document.documentElement.scrollTop; };
}
else if (document.body.clientWidth) {
    // These are for IE4, IE5, and IE6 without a DOCTYPE
    Geometry.getViewportWidth =
        function( ) { return document.body.clientWidth; };
    Geometry.getViewportHeight =
        function( ) { return document.body.clientHeight; };
    Geometry.getHorizontalScroll =
        function( ) { return document.body.scrollLeft; };
    Geometry.getVerticalScroll =
        function( ) { return document.body.scrollTop; };
}

// These functions return the size of the document. They are not window
// related, but they are useful to have here anyway.
if (document.documentElement && document.documentElemnet.scrollWidth) {
    Geometry.getDocumentWidth =
        function( ) { return document.documentElement.scrollWidth; };
    Geometry.getDocumentHeight =
        function( ) { return document.documentElement.scrollHeight; };
}
else if (document.body.scrollWidth) {
    Geometry.getDocumentWidth =
        function( ) { return document.body.scrollWidth; };
    Geometry.getDocumentHeight =
        function( ) { return document.body.scrollHeight; };
}

分享到:
评论

相关推荐

    javascript学习笔记.docx

    10) 每个类都有一个原型(prototype)对象,它具有一套属性和方法,用来共享一个类的方法和常量,还有一个constructor的属性引用构造函数。 11) JavaScript中面向对象的特性: a) 实例属性:在构造函数创建或初始化...

    JavaScript权威指南(第6版)

    8.7 函数属性、方法和构造函数 8.8 函数式编程 第9章 类和模块 9.1 类和原型 9.2 类和构造函数 9.3 JavaScript中Java式的类继承 9.4 类的扩充 9.5 类和类型 9.6 JavaScript中的面向对象技术 9.7 子类 9.8 ECMAScript...

    JavaScript权威指南(第6版)(附源码)

    8.7 函数属性、方法和构造函数 8.8 函数式编程 第9章 类和模块 9.1 类和原型 9.2 类和构造函数 9.3 JavaScript中Java式的类继承 9.4 类的扩充 9.5 类和类型 9.6 JavaScript中的面向对象技术 9.7 子类 9.8 ...

    JavaScript权威指南(第6版)中文版pdf+源代码

     8.7 函数属性、方法和构造函数188  8.8 函数式编程194  第9章 类和模块201  9.1 类和原型202  9.2 类和构造函数203  9.3 JavaScript中Java式的类继承207  9.4 类的扩充210  9.5 类和类型212  9.6 ...

    JavaScript权威指南(第6版)(中文版)

    8.7 函数属性、方法和构造函数 8.8 函数式编程 第9章 类和模块 9.1 类和原型 9.2 类和构造函数 9.3 JavaScript中Java式的类继承 9.4 类的扩充 9.5 类和类型 9.6 JavaScript中的面向对象技术 9.7 子类 9.8 ECMAScript...

    JavaScript 权威指南(第四版).pdf

     8.7 函数属性、方法和构造函数188  8.8 函数式编程194  第9章 类和模块201  9.1 类和原型202  9.2 类和构造函数203  9.3 JavaScript中Java式的类继承207  9.4 类的扩充210  9.5 类和类型212  9.6 ...

    JavaScript权威指南(第6版)中文文字版

    8.7 函数属性、方法和构造函数 188 8.8 函数式编程 194 第9章 类和模块 201 9.1 类和原型 202 9.2 类和构造函数 203 9.3 javascript中java式的类继承 207 9.4 类的扩充 210 9.5 类和类型 212 9.6 javascript中的面向...

    JavaScript权威指南(第六版) 清晰-完整

    8.7 函数属性、方法和构造函数 8.8 函数式编程 第9章 类和模块 9.1 类和原型 9.2 类和构造函数 9.3 JavaScript中Java式的类继承 9.4 类的扩充 9.5 类和类型 9.6 JavaScript中的面向对象技术 9.7 子类 9.8 ECMAScript...

    JavaScript权威指南(第6版)

    8.7 函数属性、方法和构造函数 188 8.8 函数式编程 194 第9章 类和模块 201 9.1 类和原型 202 9.2 类和构造函数 203 9.3 javascript中java式的类继承 207 9.4 类的扩充 210 9.5 类和类型 212 9.6 javascript中的面向...

    JavaScript权威指南(第6版) 中文版

    8.7 函数属性、方法和构造函数 188 8.8 函数式编程 194 第9章 类和模块 201 9.1 类和原型 202 9.2 类和构造函数 203 9.3 javascript中java式的类继承 207 9.4 类的扩充 210 9.5 类和类型 212 9.6 javascript中的面向...

    WebGIS从基础到开发实践代码(基于ArcGIS API for JavaScript)

    2.2.2ArcGIS API for JavaScript与Dojo的关系 2.3开发与调试工具 2.3.1集成开发环境 2.3.2调试工具 2.3.3Firebug 2.3.4其他工具软件 2.4Dojo基础知识 2.4.1JavaScript对象 2.4.2函数也是对象 2.4.3模拟类与继承 ...

    Web GIS从基础到开发实践 基于ArcGIS API for JavaScript

    4.2.2自定义切片地图图层——百度地图 4.2.3自定义图层——三维建筑图 4.3地图操作 4.3.1地图窗口操作 4.3.2地图属性获取 4.3.3事件处理 4.4地图参数的基本配置 4.4.1漫游与缩放动画的参数配置 4.4.2比例滚动条的...

    ActionScript开发人员指南中文版

    外部API示例:在ActionScript和Web浏览器中的JavaScript之间进行通信 第章:AIR中的XML签名验证 XML签名验证的基础知识 关于XML签名 实现IURIDereferencer接口 第章:客户端系统环境 客户端系统环境基础知识 使用...

    精通qt4编程(源代码)

    较深入地分析了Qt对象模型的一些基本知识,涉及信号和槽机制、Qt元对象系统、属性系统和对象树机制,以及部件类型和部件的几何布局等内容。 35 \ 第4章 程序主窗口—— QMainWindow 卢传富 Qt应用程序的主窗口是由多...

    精通Qt4编程(第二版)源代码

    较深入地分析了Qt对象模型的一些基本知识,涉及信号和槽机制、Qt元对象系统、属性系统和对象树机制,以及部件类型和部件的几何布局等内容。 35 \ 第4章 程序主窗口—— QMainWindow 卢传富 Qt应用程序的主窗口是由...

    PHP开发实战1200例(第1卷).(清华出版.潘凯华.刘中华).part1

    实例179 修改表单属性为弹出窗口 216 实例180 表单输入单元的文字设置 217 实例181 表单输入单元单击删除 218 实例182 表单文本输入的移动选择 219 实例183 通过下拉列表选择头像 220 3.5 CSS+DIV页面布局 222 实例...

    PHP开发实战1200例(第1卷).(清华出版.潘凯华.刘中华).part2

    实例179 修改表单属性为弹出窗口 216 实例180 表单输入单元的文字设置 217 实例181 表单输入单元单击删除 218 实例182 表单文本输入的移动选择 219 实例183 通过下拉列表选择头像 220 3.5 CSS+DIV页面布局 222 实例...

Global site tag (gtag.js) - Google Analytics