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

offset Dimensions 详解相关推荐

  1. php js offset,获取元素的偏移量offset实例详解

    问题:如果获取元素距离文档顶部的距离?[javascript] view plain copy var rect=$('#elem')[0].getBoundingClientRect(); //获取 ...

  2. Kafka offset 偏移量详解

    1 背景 Kafka是Consumer去拉Broker 中的数据,但是数据从何处开始拉是一个技术问题 为了解决这个问题场景,所以Kafka推出了偏移量的概念 2 offset 偏移量是什么 2.1 基 ...

  3. kafka consumer消费者 offset groupID详解

    kafka consumer:消费者可以从多个broker中读取数据.消费者可以消费多个topic中的数据. 因为Kafka的broker是无状态的,所以consumer必须使用partition o ...

  4. Excel的Offset函数详解

    大家好,我是永不止步的老牛 今天我们来了解下Excel的Offset函数的实用用法 Offset函数的语法是: Offset(reference, rows, cols, [height], [wid ...

  5. kafka的auto.offset.reset详解与测试

    取值及定义# auto.offset.reset有以下三个可选值: latest (默认) earliest none 三者均有共同定义: 对于同一个消费者组,若已有提交的offset,则从提交的of ...

  6. 1.12.Flink Kafka-Connector详解、Consumer消费策略设置、动态加载Topic、Consumers Offset 自动提交、Producer、容错等

    1.12.Flink Kafka-Connector详解 1.12.1.Kafka Consumer消费策略设置 1.12.2.Kafka Consumer的容错 1.12.3.动态加载Topic 1 ...

  7. 图文详解Unity3D中Material的Tiling和Offset是怎么回事

    图文详解Unity3D中Material的Tiling和Offset是怎么回事 Tiling和Offset概述 Tiling表示UV坐标的缩放倍数,Offset表示UV坐标的起始位置. 这样说当然是隔 ...

  8. Accelerate CNNs from Three Dimensions: A Comprehensive Pruning Framework详解

    Accelerate CNNs from Three Dimensions: A Comprehensive Pruning Framework详解 文章目录 Accelerate CNNs from ...

  9. js的client、scroll、offset详解与兼容性

    clientWidth:可视区宽 说明:样式宽+padding 参考:js的client详解 scrollTop : 滚动条滚动距离 说明:chrome下他会以为滚动条是文档元素的,所以需要做兼容: ...

  10. kuka机器人offset指令_KUKA机器人MADA详解.doc

    KUKA机器人MADA详解.doc &PARAM VERSION = 4.5.1 &REL 1 DEFDAT $MACHINE PUBLIC CHAR $V_R1MADA[32] $V ...

最新文章

  1. 用户进程与内核进程是一一对应的吗_用户线程、内核线程和轻量级进程
  2. 视图、索引、存储过程优缺点
  3. 全排列的生成算法:字典序法
  4. Android之靠谱的获取本地相册图片
  5. linux open函数解释,linux之open函数解析
  6. 撒贝宁探班威马体验百度Apollo L4级自动驾驶 感慨:确实震撼
  7. 【转】Delphi7程序调用C#写的DLL解决办法
  8. ubuntu 强制关闭某个程序
  9. 英伟达显卡不同架构_求历代英伟达显卡架构名称
  10. 有学生表Student, 课程表Course, 学生选课表StudentCourse
  11. 2019腾讯校招客户端方向面经(已拿offer)
  12. 避免幻读 : next-key锁与MVCC
  13. 爬虫如何爬取猫眼电影TOP榜数据
  14. 计算机utp,UTP网线
  15. 【Excel】引用人民银行同期贷款利率(基准利率)和LPR利率的利息计算器(多项目)
  16. 全景故宫--全景图片展现数字故宫
  17. 求素数的python程序,Python-求素数程序
  18. Step7中有关时间和定时器的使用和例程2
  19. 这些人都在使用超级表格
  20. 使用树莓派拍摄延时摄影视频

热门文章

  1. 心淡淡的幸福[lyb521569]
  2. 关于web中的自适应布局
  3. 那些开源程序中让人叹为观止的代码 - 1 浏览器特性判断
  4. Struts与MVC分层理解
  5. c# winform 让Form窗体上系统自带的红色关闭按钮失效,点击关闭变为隐藏
  6. PHP设计模式——状态模式
  7. Redis与Mysql双写一致性方案解析
  8. redis的批量操作命令pipeline(PHP实现)
  9. 家庭记账本开发进度6
  10. 2018.9.28 典型for循环特殊理解及其二维数组的理解