[Javascript] Detect overlapping controls?

Peter Brunone peter at brunone.com
Fri Feb 4 12:11:15 CST 2005


Somebody needs to invent a date-sensitive, top-posting sig for Hakan :)

Thanks; I'll look into these.  Although I'm starting to realize the limitations here (other windowed controls and iframes with content from different sites so I can't alter the HTML), so I may have to take a stroll down createPopup lane (IE only; I don't know what I'm going to do for Moz).

Cheers,

Peter

P.S.  Save me a seat and a cold one.

 From: "Hakan M (Backbase)" hakan at backbase.com

It is possible, in IE and Mozilla. They have proprietary functions that 
will help you.

Anyway, I'm off for the pub, so I can't help you really much right now.

But have a look at

Mozilla: document.getBoxObjectFor(oElement);
IE: oElement.getBoundingClientRect();

and they will provide you with all the stuff you need. Not that in IE, 
the offset is 2 pixels off (always).

Hope this helps.

Regards,
H

Peter Brunone wrote:
> Thanks Paul and Richard...
> 
> I guess I was looking for some magical method that would allow me to 
> do this without iterating through *every* element on the page. Perhaps 
> that's not a possibility right now, and I just need to get down and 
> dirty with the DOM. As usual, I'm sure PPK's stuff will prove helpful.
> 
> Cheers,
> 
> Peter
> 
> *From*: Paul Novitski paul at novitskisoftware.com 
> 
> 
> At 08:27 PM 2/3/2005, Peter Brunone wrote:
> > Is it possible, with an absolutely-positioned element, to
> >determine what controls (either absolutely or relatively positioned)
> >overlap its current area?
> 
> Peter,
> 
> As far as I know you can determine the dimensions and position in the
> window of any element on the page, regardless of how it was
> positioned. Peter-Paul Koch's got some nifty little functions for
> determining position on http://www.quirksmode.org/ (navigate to Javascript
> : DHTML : Find position) Then it's a simple matter of iterating through
> all the elements on the page, doing the necessary arithmetic to discover if
> any overlap your target element.
> 
> Upon reflection, it seems to me that two boxes overlap if any one corner of
> either box lies between the top and bottom AND between the left and right
> edges of the other box. That logic would require eight tests per pair of
> boxes to prove that they didn't overlap, testing each corner of both boxes
> to see if it lay within the other box. Perhaps you can reduce that to
> something more elegant!
> 
> Well, let's see: in four tests you can find out whether:
> - the top of box A lies below the bottom of box B, or
> - the bottom of box A lies above the top of box B, or
> - the left edge of A lies to the right of B's right edge, or
> - the right edge of A lies to the left of B's left edge.
> If any of those are true, the boxes can't overlap. If all are false, I
> believe they must overlap. N'est ce pas?
> 
> Paul
> 
> 
> ------------------------------------------------------------------------
> 
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript
_______________________________________________
Javascript mailing list
Javascript at LaTech.edu
https://lists.LaTech.edu/mailman/listinfo/javascript


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.evolt.org/pipermail/javascript/attachments/20050204/484ad96a/attachment.htm>


More information about the Javascript mailing list