标签:javascript jquery web
1, top and left relative to the document
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;
var viewportOffset = el.getBoundingClientRect(); // these are relative to the viewport var top = viewportOffset.top; var left = viewportOffset.left;
var topToParent = $('#elementID').position().top; var leftToParent = $('#elementID').position().left;
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;
difference of top and left between Javascript and Jquery
标签:javascript jquery web
原文地址:http://blog.csdn.net/alexwang1983/article/details/46332795