offset Dimensions 详解
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 详解的更多相关文章
- kafka的auto.offset.reset详解与测试
1. 取值及定义 auto.offset.reset有以下三个可选值: latest (默认) earliest none 三者均有共同定义: 对于同一个消费者组,若已有提交的offset,则从提交的 ...
- 图文详解Unity3D中Material的Tiling和Offset是怎么回事
图文详解Unity3D中Material的Tiling和Offset是怎么回事 Tiling和Offset概述 Tiling表示UV坐标的缩放倍数,Offset表示UV坐标的起始位置. 这样说当然是隔 ...
- JQ的offset().top与js的offsetTop区别详解
一.前言 最近在做一个图片懒加载的插件,就纵轴(Y轴)而言,我需要时时获取图片的上偏移量,好判断是否已进入视图区域,而我所理解的是offsetTop应该是跟offset().top一样的,然后陷入了因 ...
- JQ的offset().top与JS的getBoundingClientRect区别详解,JS获取元素距离视窗顶部可变距离
壹 ❀ 引 我在 JQ的offset().top与js的offsetTop区别详解 这篇博客中详细分析了JQ方法offset().top与JS属性offsetTop的区别,并得出了一条offset( ...
- js的client、scroll、offset详解与兼容性
clientWidth:可视区宽说明:样式宽+padding参考:js的client详解 scrollTop : 滚动条滚动距离说明:chrome下他会以为滚动条是文档元素的,所以需要做兼容:var ...
- C#进阶系列——WebApi 接口返回值不困惑:返回值类型详解
前言:已经有一个月没写点什么了,感觉心里空落落的.今天再来篇干货,想要学习Webapi的园友们速速动起来,跟着博主一起来学习吧.之前分享过一篇 C#进阶系列——WebApi接口传参不再困惑:传参详解 ...
- Android图片缓存之Bitmap详解
前言: 最近准备研究一下图片缓存框架,基于这个想法觉得还是先了解有关图片缓存的基础知识,今天重点学习一下Bitmap.BitmapFactory这两个类. 图片缓存相关博客地址: Android图片缓 ...
- redis配置详解
##redis配置详解 # Redis configuration file example. # # Note that in order to read the configuration fil ...
- Linux C 字符串函数 sprintf()、snprintf() 详解
一.sprintf() 函数详解 在将各种类 型的数据构造成字符串时,sprintf 的强大功能很少会让你失望. 由于 sprintf 跟 printf 在用法上几乎一样,只是打印的目的地不同而已,前 ...
随机推荐
- Android基础相关面试问题-binder面试问题详解
Linux内核的基础知识: 进程隔离/虚拟地址空间:在操作系统中为了保护某个进程互不干扰就设计了一个叫“进程隔离”的技术,防止进程A可以操作进程B的数据.而进程隔离技术用到了虚拟地址空间,进程A的虚拟 ...
- Android异常与性能优化相关面试问题-内存管理面试问题详解
内存管理机制概述: 分配机制:操作系统会为每一个进程分配一个合理的内存大小,从而保证每一个进程能够正常的运行,不至于内存不够使用,或者某个进程占用过多的内存. 回收机制:在系统内存不足的时候,系统有一 ...
- 19.8.28 flutter学习笔记
1:字符串的操作 length打印字符串的长度.“isEmpty”判断字符串是否为空. “contains()是否包含某个字符串”.”substring(startIndex,endIndex)截取一 ...
- 最简单之安装JDK
参考:https://www.cnblogs.com/lizhewei/p/11181082.html 1,百度搜索jdk 2,官网下载 jdk-8u161-linux-x64.rpm 或者jdk-8 ...
- 逻辑卷管理(LVM)
LVM:Logical Volume Management 逻辑卷管理 LVM是建立在硬盘和分区之上的一个逻辑层,来提高磁盘分区管理的灵活性. 传统磁盘管理:我们上层是直接访问文件系统,从而对底层的物 ...
- 初始Ajax学习笔记
前端: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <!--引入 ...
- pycharm运行程序,总是出现IPthony界面(IPython 6.2.1 -- An enhanced Interactive Python. Type '?' for help. PyDev console: using IPython 6.2.1)
解决方式如下: 取消即可.
- 【jqGrid】翻页获取选中的值
1.实现效果: 点击确定所选按钮之后,获取翻页选中的题库表号 2.关键代码 onSelectAll: function (aRowids, status) { }, onSelectRow: func ...
- mongodb 批量添加、修改和删除
1.使用MongoTemplate a.批量插入 Insert a Collection of objects into a collection in a single batch write to ...
- SQL Server 删除日志文件
-- 查询日志文件名,用于下面删除 USE [data_name] GO SELECT file_id, name FROM sys.database_files /*删除指定数据库的日志文件*/ U ...