博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
offset Dimensions 详解
阅读量:5093 次
发布时间:2019-06-13

本文共 2081 字,大约阅读时间需要 6 分钟。

1. <Professional JavaScript for web developer>   

Offset dimensions incorporate all of the visual space that an element takes up on the screen. An element's visual space on the page is made up of its height and width, including all padding, scrollbars, and borders (but not including margin). The following four properties are used to retrieve offset dimensions:

  • offsetHeight : The amount of vertical space, in pixels, taken up by the elements, including its height, the height of a horizontal scrollbr (if visible), the top border height, and the bottom border height.
  • offsetWidth : The amount of horizontal space taken up by the element, including its width, the width of a vertical scrollbar (if visible), the left border width, and the right border width. 
  • offsetLeft : The number of pixels between the element's outside left border and the containing element's inside left border.
  • offsetTop : The number of pixels between the element's outside top border and the containing element's inside top border.

Figure 12-1 illustrates the various dimensions these properties represent.

 

2. MDN

The HTMLElement.offsetLeft read-only method returns the number of pixels that the upper left corner of the current element is offset to the left within the HTMLElement.offsetParent node.

The HTMLElement.offsetParent read-only property returns a reference to the object which is the closest positioned containing element. If the element is non-positioned, the nearest table cell or root element is the offsetParent. offsetParent returns null when the element has style.display set to "null";

 

3. Test

Test code is in here [http://runjs.cn/code/fcotalf7]

 

1. Note that offsetLeft is read-only , therefore it can't be set like left;

2. JavaScript通过element.style.left访问left属性,style属性的一点注意问题参见  。如果left写在<style>或外部样式表中,JavaScript将无法访问到left的值(undefined)。所以element.style.left = parseInt(element.style.left) + 10 + "px"; 代码是无法修改left的值。 正确的代码是element.style.left = element.offsetLeft + "10" + "px";  element.offsetLeft是可以通过JavaScript获取到其值的,并且代码最后是作用在行内元素上 !

转载于:https://www.cnblogs.com/linxd/p/4539399.html

你可能感兴趣的文章
C#一个FTP操作封装类FTPHelper
查看>>
更换yum源
查看>>
上一页 下一页
查看>>
Linux运维基础入门(二):网络基础知识梳理02
查看>>
你所不知道的 CSS 阴影技巧与细节
查看>>
MyBatis框架的使用及源码分析(三) 配置篇 Configuration
查看>>
20172319 实验三《查找与排序》实验报告
查看>>
构造函数的继承
查看>>
Nginx的虚拟主机配置
查看>>
overflow 属性
查看>>
Mychael原创题 洛谷T23923 Mychaelの水题 【题解】
查看>>
Objective-C 协议(protocol)
查看>>
Android自定义进度条
查看>>
java虚拟机深入理解Java虚拟机:JVM高级特性与最佳实践(第2版)
查看>>
struts返回对象json格式数据
查看>>
[[UIScreen mainScreen] bounds] 返回的屏幕尺寸不对
查看>>
Scrapy爬取小说简单逻辑
查看>>
《移动平台应用开发实践》教学进程(12周)
查看>>
OracleDG主库丢失归档增量同步
查看>>
32位的PLSQL登录64位的ORA11g有关问题
查看>>