472,969 Members | 1,533 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,969 software developers and data experts.

mousemove for overlapping divs

hi. i've got a problem as follows, to which i can't find a solution to:

i've got two divs, which are completely independent of each other
(neither is a parent of child of another).
they're positioned (either absolutely or relatively) in a way that they
overlap each other. when i assign an onmousemove event to them, only one
of them catches it.
any capturing and/or bubbling is beeing performed by parents of the div
that caught the mousemove event why the second div ignores it completely.
this happens both in firefox and ie (i didn't check other browsers), so
it's apparently not a browser problem.
is there a method to make them both catch the mousemove (or any other)
event at the same time?

thank you in advance for any help.

regards
Jakub Łukomski
Jun 12 '06 #1
2 4575
Jakub Lukomski wrote:
hi. i've got a problem as follows, to which i can't find a solution to:

i've got two divs, which are completely independent of each other
(neither is a parent of child of another).
they're positioned (either absolutely or relatively) in a way that they
overlap each other. when i assign an onmousemove event to them, only one
of them catches it.
any capturing and/or bubbling is beeing performed by parents of the div
that caught the mousemove event why the second div ignores it completely.
this happens both in firefox and ie (i didn't check other browsers), so
it's apparently not a browser problem.
is there a method to make them both catch the mousemove (or any other)
event at the same time?
The only way I know of is to store the location of the divs in page
co-ordinates (top, right, bottom, left) then have an onmousemove
function that checks to see which divs the cursor is over at each move.

You can use onmouseover/out on the divs to start/stop the onmousemove
function so that it only runs when the cursor is actually over one of
the relevant divs.

Here is a very simple example:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<title>mouseover play</title>
<style type="text/css">
body {margin: 0; padding:0;}
#container {
position: relative;
width: 200px; height: 200px;
background-color: #ddd;
}
#redDiv {
width:100px; height:100px;
border:1px solid red;
position: absolute;
top: 0px; left: 0px;
}
#blueDiv {
width:100px; height:100px;
border:1px solid blue;
position: absolute;
top: 50px; left: 50px;
}
</style>

<div id="container"
onmouseover="isOver.start();"
onmouseout="isOver.stop();"

<div id="redDiv">red div</div>
<div id="blueDiv">blue div</div>
</div>
Tracking&nbsp;<span id="tOnOff"><b>OFF</b></span>

<script type="text/javascript">
var isOver = (function()
{
var docBody = document.body || document.documentElement;

// Hard coded here but would calculate dynamically in real life
var zones = {}; // References to drop zones
zones.elA = document.getElementById('redDiv');
zones.elB = document.getElementById('blueDiv');
zones.elA.edges = {top:0, right:100, bottom:100, left:0};
zones.elB.edges = {top:50, right:150, bottom:150, left:50};

function cursorPos(e){
var e = e || window.event;
var posXY = {x:0, y:0};
if (e.pageX || e.pageY) {
posXY.x += e.pageX;
posXY.y += e.pageY;
} else if (e.clientX || e.clientY){
posXY.x += e.clientX + document.body.scrollLeft;
posXY.y += e.clientY + document.body.scrollTop;
}
return posXY;
}
function trackCursor(e){
var e = e || window.event;
var posXY = cursorPos(e);
var dz;
for (el in zones){
dz = zones[el];
if ( pointInRect(posXY, dz.edges) ) {
dz.innerHTML = 'over';
dz.style.backgroundColor = '#aae';
} else {
dz.innerHTML = 'out';
dz.style.backgroundColor = '#fff';
}
}
}
function pointInRect(pos, rect){
return (
pos.x > rect.left && pos.x < rect.right
&& pos.y > rect.top && pos.y < rect.bottom );
}
return ({
start : function() {
docBody.onmousemove = trackCursor;
document.getElementById('tOnOff').innerHTML =
"<b>ON</b>";
},
stop : function() {
docBody.onmousemove = null;
document.getElementById('tOnOff').innerHTML =
"<b>OFF</b>";
}
});
})();
</script>
</html>
--
Rob

Jun 13 '06 #2
RobG wrote:
The only way I know of is to store the location of the divs in page
co-ordinates (top, right, bottom, left) then have an onmousemove
function that checks to see which divs the cursor is over at each move. yes, that's exactly the way i was thinking of solving this if there's no
other way...
You can use onmouseover/out on the divs to start/stop the onmousemove
function so that it only runs when the cursor is actually over one of
the relevant divs.

i didn't actually think of turning mouseover off for a div. and this
solves my problem PERFECTLY (in this situation at least).

thanks for help

Jakub Łukomski
Jun 13 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Peter Jenkins | last post by:
I have some divs I am using to get a two column layout for a section of a page, like so; <div1> <div2> <div3> blah blah blah blah blah blah blah blah...
1
by: Mitch | last post by:
I have 2 rectangle images. 1 with a box in the upper left corner and the other with a box in the lower right hand corner. Both images are the same size. I would like to display these 2 images so...
8
by: gpbmike | last post by:
I'm wondering if anyone else has had this problem before. Every now and then a div on my page will overlap with another. Thi only happens in firefox (vs. IE and Safari) and it corrects itself whe...
2
by: Daphne Tregear | last post by:
Is there every anything other than woe with IE...? I'm working on a redesign for my hobby pages in my personal home space before re-exporting them back to where they belong. I've based the...
2
by: Kalvin | last post by:
I am very new to CSS and am trying to set up 2 divs in the same space on the page. The idea is that div1 will be an informational message only displayed sometimes. When there isn't a message to...
3
by: michelle koen | last post by:
Hi Folks, on <a href="http://donbrice.com/new/page.php?section=schools">this page</a> and for all the sections I can't get Safari(2.02) or Firefox-PC(1.5) or the latest vers. of Opera-Mac to...
1
by: spolsky | last post by:
hi, i have the following html. if padding given for the span it overlaps the divs within IE 6, FireFox 1.5 and Opera 9.01. i don't want to give sizes manually. how could i prevent this...
2
by: Liam Gibbs | last post by:
Hello everyone. I'm having a problem with a web page. What I have is one DIV (a header) overlapping the border around another DIV (a menu block). I want this, because I want to put this header...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
3
by: GKJR | last post by:
Does anyone have a recommendation to build a standalone application to replace an Access database? I have my bookkeeping software I developed in Access that I would like to make available to other...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.