Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Intersection of DIVS

Reply
Thread Tools

Intersection of DIVS

 
 
sicapitan
Guest
Posts: n/a
 
      08-21-2006
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?

 
Reply With Quote
 
 
 
 
Randy Webb
Guest
Posts: n/a
 
      08-21-2006
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.

--
Randy
comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
 
Reply With Quote
 
 
 
 
sicapitan
Guest
Posts: n/a
 
      08-22-2006
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!

Randy Webb wrote:
> 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.
>
> --
> Randy
> comp.lang.javascript FAQ - http://jibbering.com/faq & newsgroup weekly
> Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
swapping divs -- when divs NOT positioned absolutely.. maya Javascript 4 11-16-2007 05:11 PM
Line intersection detection.... SPG Java 15 11-07-2006 10:02 AM
Managing divs within divs.... rich HTML 0 02-02-2006 07:38 PM
intersection simulation zaebos@gmail.com Java 6 09-14-2005 06:12 PM
ray/triangle intersection in java bob@coolgroups.com Java 1 04-11-2005 01:08 AM



Advertisments