WebFX WebBoard
Message Thread:
View All Messages
Back to WebFX
 Question about div layers overlapping?, Steve, July 19, 2003
     Re:Question about div layers overlapping?, Chris, July 19, 2003
         Re:Question about div layers overlapping?, Erik Arvidsson, July 19, 2003

Subject: Re:Question about div layers overlapping? From: Erik Arvidsson Date: July 19, 2003
Use offsetLeft, offsetTop, offsetWidth and offsetHeight (when getting) and style.left (etc) when setting. This works in ALL modern browsers. Even in IE6 ;-)

erik

_______________________________________________________

If you want to know if divs overlap, check their positions...
For example, if the left position of the second div is less than the left position of the first div plus its width, then they are overlapping horizontally...
To check, just inquire on their positions and widths...
var div1_left_pos = document.getElementById("div1").style.pixelLeft;
var div1_width = document.getElementById("div1").style.pixelWidth;
var div2_left_pos = document.getElementById("div2").style.pixelLeft;
if (div2_left_pos < div1_left_pos + div1_width) alert('overlapping');

Obviously this is only checking if the second div is overlapping the first one horizontally, but i imagine you'll get the jist...
Also, this is just for ie (which, being a mac person myself i utterly despise and use mozilla for everything :) so you might (to make it cross browser) parseInt on div1.style.left etc to check which is greater than the other etc...
Also, when you implement the dragging, you can use the same or, if you give a variable which controls where the div is in relation to the mouse, check the value of that with respect to the height/width and top/left of the other div respectively...
Hope that helps.. been a long time since i've posted an answer on this board - coming up for three years i think (hope erik and emil remember me from a couple of year before the site changed to what it is now - 'member when some asian guy ripped off the front page and said it was his own work? :) )

Chris
From: Steve
Sent: July 19, 2003
Subject: Re:Question about div layers overlapping?

Is there a way to programatically check is two layers overlap?
Check out this page and you will see.
http://soneal.no-ip.com:2900/test/calendar.cfm
I am reading the appointments from a DB and need to know if they overlap. I will eventually add drag and drop to the Divs, but I will need to know if they overlap.






Reply
Name: 
Email: 
Subject: 

Enter your reply to this message below. HTML tags are not supported but words that start with http://, ftp:// or mailto: are converted to links.


View All Messages
Back to WebFX