difference of top and left between Javascript and Jquery
来源:互联网 发布:avmoo新域名 2017 编辑:程序博客网 时间:2024/05/08 17:11
1, top and left relative to the document
.offset()
Get the current coordinates of the first element, or set the coordinates of every element, in the set of matched elements, relative to the document.
var top = $('#elementID').offset().top;var left = $('#elementID').offset().left;
native javascript
getBoundingClientRect, top-left relative to the top-left of the viewport.
var viewportOffset = el.getBoundingClientRect();// these are relative to the viewportvar top = viewportOffset.top;var left = viewportOffset.left;
2, top and left relative to the parent
jquery
.position()
Get the current coordinates of the first element in the set of matched elements, relative to the offset parent.
var topToParent = $('#elementID').position().top;var leftToParent = $('#elementID').position().left;
native javascript.offsetTop, .offsetLeft
The HTMLElement.offsetTop read-only property returns the distance of the current element relative to the top of the offsetParent node.
var topToParent = element.offsetTop;var leftToParent = element.offsetLeft;
3, Border native javascript
element.clientTop;
The width of the top border of an element in pixels. It does not include the top margin or padding. clientTop is read-only.
see: https://developer.mozilla.org/en-US/docs/Web/API/Element/clientTop
0 0
- difference of top and left between Javascript and Jquery
- The difference between JQuery and JQuery.fn
- Difference between forward and include of RequestDispatcher
- difference between data() and c_str() of basic_string
- Difference between OnPaint and OnDraw of MFC
- The difference between JS and jQuery
- Difference between Properties and Attributes in JavaScript
- Difference between prototype and this in JavaScript
- The difference between (()) and ().
- difference between "<" and "<<"
- In SQL, what is the difference between a left join and a left outer join?
- What is the difference between left join and left outer join?
- The difference of overriding between C# and Java
- the difference between ClientID and ID of web control
- String and some of the difference between StringBuffer
- The difference of SE Detail UI between 2.4 and 4.0
- one mail for difference between LOCAL_LDLIBS and LOCAL_SHARED_LIBRARIES of Android
- The difference of Post-Secondary education between USA and China
- magento 获取自定义产品属性和属性值
- sql查询语句的一些简单优化措施(持续补充)
- 平安科技移动开发二队技术周报(第三期)
- mysql将字符转换成数字
- 利用solrj操作solr的API
- difference of top and left between Javascript and Jquery
- [leetcode] 73.Set Matrix Zeroes
- 用Varnish和Memcached缓存给WordPress网站提速-内存级加速
- 在一个Activity里面的TextView上面添加网页链接,启动后到另一个Activity里面!
- 平安科技移动开发二队技术周报(第四期)
- 对一串数字采用相应的加密策略后传输的Java实现代码
- 第十七篇 简单的自我介绍
- android小程序整理笔记
- JPA中one-to-one关系的单向映射示例