This is an archived snapshot of W3C's public bugzilla bug tracker, decommissioned in April 2019. Please see the home page for more details.

Bug 23171 - add js properties absoluteLeft, absoluteTop, offsetWidth, offsetHeight
Summary: add js properties absoluteLeft, absoluteTop, offsetWidth, offsetHeight
Status: RESOLVED INVALID
Alias: None
Product: WHATWG
Classification: Unclassified
Component: JavaScript (show other bugs)
Version: unspecified
Hardware: PC other
: P2 normal
Target Milestone: Unsorted
Assignee: Mathias Bynens
QA Contact: sideshowbarker+javascript
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-09-05 22:42 UTC by Jim Michaels
Modified: 2014-06-21 12:53 UTC (History)
2 users (show)

See Also:


Attachments

Description Jim Michaels 2013-09-05 22:42:32 UTC
my platform is win7 sp1 64-bit and xp sp3 32-bit.
this bug is forked from bug https://www.w3.org/Bugs/Public/show_bug.cgi?id=22772
.clientWidth, .clientHeight, offsetHeight, offsetWidth, offsetLeft seem to (but not really) solve 3 of the 4 issues for js in that bug.
in order to make use of them, some sort of while loop or recursion needs to be used to walk through the parent elements and sum up the offsetLeft and offsetTop in order to obtain an absolute position. could something like .absoluteLeft and .absoluteTop be made available as a property for every element in the document?
also, if offsetTop and offsetLeft js properties are not currently cross browser, I would like it to be so.

that is the enhancement request. the use case is the ability to relatively position elements from another element, and as it turns out, the way things are now, css z-index makes no difference in the picture as I once thought.

this bug is regarding the js portion and needing to have always-on absolute element position.

function getOffsetLeft(el) {
	var sum=el.offsetLeft;
	while (el.offsetParent) {
		el=el.offsetParent;
		sum += el.offsetLeft;
	}
	return sum;
}
function getOffsetTop(el) {
	var sum=el.offsetTop;
	while (el.offsetParent) {
		el=el.offsetParent;
		sum += el.offsetTop;
	}
	return sum;
}
//not sure how to make this into a built-in method of element.
also, this doesn't work in every case, fails and gives me 0's in http://jesusnjim.com/test/css-flex.html for #i3.
Comment 1 Mathias Bynens 2014-06-21 12:53:52 UTC
This is outside the scope of the JavaScript / Web ECMAScript spec. See <http://javascript.spec.whatwg.org/#goals>.

To propose new features to the ECMAScript language, please file a bug on https://bugs.ecmascript.org/.