Intersection of DIVS

S

sicapitan

Hi There :)

Is it possible to get the 4 corners where 2 dives intersect? I'm
making a table-ish system and som drag and drop elements need to snap
to the area intersecting between 2 divs.

I don't know if this is possible?
 
R

Randy Webb

sicapitan said the following on 8/21/2006 5:18 AM:
Hi There :)

Is it possible to get the 4 corners where 2 dives intersect? I'm
making a table-ish system and som drag and drop elements need to snap
to the area intersecting between 2 divs.

I don't know if this is possible?

Yes, quite possible. You need to know the top left corner of the two
divs (that is not trivial but you can use Matt Kruse's Object Position
library to find those):

<URL: http://www.javascripttoolbox.com/lib/objectposition/>

After knowing the top left corners of both you go with the one that is
the "lowest" on the screen, meaning further down the page. Once you know
which is the lowest, you look to see which is the left most. If the
lower one is to the right, then you want the top and left of that Div to
be the top and left of your dropped element.

If the lower div is to the left, then you want the intersection of the
two divs. The top of the lower div and the left of the upper div will
give you the intersection point. That would be the top/left of your
dropped element.

You would need to check also to make sure the two div tags are
overlapped. That would require knowing the height and width of the divs.

P.S. Knowing the top and left of both divs you could even stretch/shrink
your dropped element to fit into the overlap box and fill it.
 
S

sicapitan

Ahhhh great, thanks Randy :) I plan to do this a number of times and
to build the divs in rows and columns which are configurable in width.
This library looks like just what I'm after. This is year 9 maths, I'm
surprised at myself for not thinking more on this one, thanks!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top