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获取到其值的,并且代码最后是作用在行内元素上 !

offset Dimensions 详解的更多相关文章

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

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

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

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

  3. JQ的offset().top与js的offsetTop区别详解

    一.前言 最近在做一个图片懒加载的插件,就纵轴(Y轴)而言,我需要时时获取图片的上偏移量,好判断是否已进入视图区域,而我所理解的是offsetTop应该是跟offset().top一样的,然后陷入了因 ...

  4. JQ的offset().top与JS的getBoundingClientRect区别详解,JS获取元素距离视窗顶部可变距离

     壹 ❀ 引 我在 JQ的offset().top与js的offsetTop区别详解 这篇博客中详细分析了JQ方法offset().top与JS属性offsetTop的区别,并得出了一条offset( ...

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

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

  6. C#进阶系列——WebApi 接口返回值不困惑:返回值类型详解

    前言:已经有一个月没写点什么了,感觉心里空落落的.今天再来篇干货,想要学习Webapi的园友们速速动起来,跟着博主一起来学习吧.之前分享过一篇 C#进阶系列——WebApi接口传参不再困惑:传参详解  ...

  7. Android图片缓存之Bitmap详解

    前言: 最近准备研究一下图片缓存框架,基于这个想法觉得还是先了解有关图片缓存的基础知识,今天重点学习一下Bitmap.BitmapFactory这两个类. 图片缓存相关博客地址: Android图片缓 ...

  8. redis配置详解

    ##redis配置详解 # Redis configuration file example. # # Note that in order to read the configuration fil ...

  9. Linux C 字符串函数 sprintf()、snprintf() 详解

    一.sprintf() 函数详解 在将各种类 型的数据构造成字符串时,sprintf 的强大功能很少会让你失望. 由于 sprintf 跟 printf 在用法上几乎一样,只是打印的目的地不同而已,前 ...

随机推荐

  1. Can you answer these queries I SPOJ - GSS1 (线段树维护区间连续最大值/最大连续子段和)

    You are given a sequence A[1], A[2], ..., A[N] . ( |A[i]| ≤ 15007 , 1 ≤ N ≤ 50000 ). A query is defi ...

  2. JAVA WEB初接触——简单的MVC架构

    1.概述 之前有过开发web的经验,因此我不会向无头苍蝇一般,心里还是有点数的

  3. HDU - 4992 Primitive Roots (原根)

    模板题,可用于求一个数的所有原根. #include<bits/stdc++.h> using namespace std; typedef long long ll; ,inf=0x3f ...

  4. .NET Core 3时代!如何使用DevExpress WPF创建应用

    DevExpress广泛应用于ECM企业内容管理. 成本管控.进程监督.生产调度,在企业/政务信息化管理中占据一席重要之地.通过DevExpress WPF Controls,您能创建有着强大互动功能 ...

  5. [Functional Programming] Examples: When and Unless

    /** * When */ const _branch = (x) => { const result = (x && x.isPublic) ? dissoc('private ...

  6. LibreOffice/Calc:在表格中始终显示某列/某行

    本文适用于LibreOffice Calc 5.1.6.2 + Ubuntu 16.04,熊猫帮帮主@cnblogs 2018/3/5 编写表格时,我们常常使用表格最左侧的一列和最上方的一行作为序号列 ...

  7. cookbook 10.1生成随机密码

    任务: 随机地创造出新密码.比如,有时需要给新的用户账号分配新的密码. 解决方案: from random import choice import string def GenPasswd(leng ...

  8. Shell登陆

    Shell登录信息 注:只对本地终端起作用,远程终端不起作用(也就是说这个文件对远程登录是无效的). 修改后: 输出: 注:这里在配置文件中添加\l之后会显示终端(这里为终端1),按住Alt+F2可以 ...

  9. noi.ac #543 商店

    我们考虑可并堆维护,从深到浅贪心选取. 用priority_queue启发式合并的话,是60pts: #include<iostream> #include<cstdio> # ...

  10. C语言中的位域[转]

    有些信息在存储时,并不需要占用一个完整的字节,而只需要一个或几个二进制位即可;比如:在存放一个开关量时,只有0和1两种状态,只需要使用一个二进制位即可存储;为了节省存储空间,C语言提供了一种数据结构, ...