How to determine an absolute-positioned element's container
I have a custom control that needs to render a pop-up window directly
below its "main" control body (a DIV element). The problem I'm running
into is how to set the pop-up coordinate location if the control has no
"knowledge" of the its container settings.
For example, take this section of code:
// library call to extract document-based coordinates (returns object with
X and Y fields) of the "controlBodyElement" (a DIV)
var pt = some.library.getDocumentPosition(controlBodyElement)
// frame (the "popup") is a DIV pointer
frame.style.position = "absolute"
frame.style.top = pt.y + controlBodyElement.clientHeight + 1 + "px" //
Line "A"
// frame.style.top = "0px" // Line "B" -- finds the relativity point of
absolute-position
Line "A" - causes the popup to be rendered way below the controlBodyElement
Line "B" - renders the popup way above the controlBodyElement.
Q: what element setting/attribute should be searched for in the DOM tree
to determine which element some absolute-positioned child is being
anchored relative to?
UPDATE: I think if someone can explain to me what page mechanics would
cause an absolute-positioned element (using top = 0px) to be rendered
halfway down the page (instead of the top) then I can write the logic to
sort things out; I'm just not sure I need to be looking for...
No comments:
Post a Comment