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 在用法上几乎一样,只是打印的目的地不同而已,前 ...
随机推荐
- CSS——字体大小最常用的单位
px (像素): 将像素的值赋予给你的文本.这是一个绝对单位, 它导致了在任何情况下,页面上的文本所计算出来的像素值都是一样的. ems: 1em 等于我们设计的当前元素的父元素上设置的字体大小 (更 ...
- windows下基于IIS配置ssl证书遇到的坑
前几天配置windows下基于IIS配置ssl证书 完全按照步骤执行 绑定https网址后,一直显示:无法访问此网站 检查了443端口,还有防火墙限制,没发现什么 足足困扰了我好几天 后来突然想到前不 ...
- iOS View的一些操作定义为宏
#define ViewOf(__View__,__TAG__) [__View__ viewWithTag:__TAG__]#define LabelOf(__View__,__TAG__) ((U ...
- MySQL的分表与分区
MySQL分表分区是解决大数据量导致MySQL性能低下的两种方法. 什么是MySQL分表 从表面意思上看,MySQL分表就是将一个表分成多个表,数据和数据结构都有可能会变.MySQL分表分为垂直分表和 ...
- Android Multiple dex files define 解决包冲突
这段时间有一个新需求,安卓App通过URL在线预览PDF.选择使用并倒入PdfViewPager库时,报了如下异常: jdmerchants:transformDexArchiveWithExtern ...
- 如何查询Office版本号
造冰箱的大熊猫@cnblogs 2019/1/28 如何查询当前所用Microsoft Office的版本信息? 以Word 2007为例,点击程序左上角的Office图标,在弹出的菜单中选择“Wo ...
- 原创:实现atoi函数
#include <stdio.h> #include <stdlib.h> #include <limits.h> int my_atoi(char *str) ...
- BOM基础笔记
BOM基础 BOM对浏览器的一些操作 1.打开.关闭窗口 •open –蓝色理想运行代码功能 window.open('http://www.baidu.com/', '_self'); <!d ...
- Spring Boot教程(三十五)使用MongoDB数据库(1)
MongoDB简介 MongoDB是一个基于分布式文件存储的数据库,它是一个介于关系数据库和非关系数据库之间的产品,其主要目标是在键/值存储方式(提供了高性能和高度伸缩性)和传统的RDBMS系统(具有 ...
- Java集合框架之简述
Java集合框架简述 Java中的集合类是一种工具类,就像是容器,存储任意数量的具有共同属性的对象,集合框架是一个用来代表和操纵集合的统一架构,包含如下部分: 1.接口: 接口是代表集合的抽象数据类型 ...