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. 数据库允许空值(null),往往是悲剧的开始(1分钟系列)

    数据库字段允许空值,会遇到一些问题,此处包含的一些知识点,和大家聊一聊. 数据准备: create table user ( id int, name varchar(20), index(id) ) ...

  2. mybatis总体分析

    Mybatis是一个半orp框架,说是半,也就是不完全是,还有很多地方是需要开发人员完成的.发现很多互联网公司使用Mybatis,而不是hibernate.应该是因为Mybatis不但有orp的优势, ...

  3. Linux之top 监视系统任务的工具

    top 监视系统任务的工具: 和ps 相比,top是动态监视系统任务的工具,top 输出的结果是连续的:  top 命令用法及参数: top 调用方法: top 选择参数 参数: -b  以批量模式运 ...

  4. 第二章 Vue快速入门--12 事件修饰符的介绍

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8&quo ...

  5. Java程序中实现 MySQL数据库的备份与还原

    案例代码: 数据库备份 //mysqldump -h端口号 -u用户 -p密码 数据库 > d:/test.sql --备份D盘 //备份 public static void dataBase ...

  6. pytorch tensor 维度理解.md

    torch.randn torch.randn(*sizes, out=None) → Tensor(张量) 返回一个张量,包含了从标准正态分布(均值为0,方差为 1)中抽取一组随机数,形状由可变参数 ...

  7. 【Python之路】特别篇--Redis

    NoSQL(NoSQL = Not Only SQL ),意即“不仅仅是SQL”,泛指非关系型的数据库 随着互联网web2.0网站的兴起,传统的关系数据库在应付web2.0网站,特别是超大规模和高并发 ...

  8. python Print 输出

    print 默认输出是换行的,如果要实现不换行需要在变量末尾加上逗号 , #!/usr/bin/python # -*- coding: UTF-8 -*- x="a" y=&qu ...

  9. memcpy 与strcpy的区别

      C/C++中mencpy的代码实现:https://www.cnblogs.com/goul/p/10191705.html C/C++中strcpy的代码实现:https://www.cnblo ...

  10. cookbook 6.2 定义常量

    任务: 需要定义一些模块级别的变量(比如命名的常量),而且客户代码无法将其重新绑定: 解决方案: #coding = utf-8 class _const(object): class ConstEr ...