Forum Moderators: open

Message Too Old, No Replies

Simulate Mouseovers

Manually passing coordinates to mouseover

         

mennis

10:42 pm on Apr 22, 2004 (gmt 0)

10+ Year Member



I'm wondering if there is any way to simulate mouseover events. I want to capture a range of X,Y coordinates and then feed that array to a mouseover function to see if it matches multiple objects on the page.

I don't need it to do anything other than to give me the object id for each object that falls within the range provided.

We are already detecting mouseovers on individual objects within a div (by div id) and capturing the X,Y coordinates. I just need to know if you can trick the browser into thinking it is over something with just the range and adding matches to a new array of matched objects.

Anyone have any ideas/suggestions?

Thank you!

Bernard Marx

1:31 pm on Apr 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Internet Explorer has the rather handy function,elementFromPoint(x,y)

This gives the element at the screen point(x,y). If there are layered elements, it gives the topmost.

For the rest it's going to be trickier. You'll indeed have to loop through your elements array, testing to see if one contains that point.

That's assuming that your elements are absolutely positioned, L,T,W & H properties held directly on the style attribute (not sheet). It is (almost) entirely possible, even if the elements are part of the flow, with dimensions dictated by content. Then you'd need to get the offset properties. The next problem then, is that you'll need to make sure that your offset L & T are given from the body element, which requires a carefully crafted function.

Sorry for the vagueness. Here's a relevant link:

[quirksmode.org ]

Let us know how you get on.

mennis

3:55 pm on Apr 23, 2004 (gmt 0)

10+ Year Member



Thanks Bernard!

The elementFromPoint(x,y) funtion is very helpful. It solves about 80% of my problem, but I'm left with the elements on the lower layers. I need to match them all. :(

And thank you for the resource link, also very helpful. Very informative and easy to follow.

Appreciate the help!

Bernard Marx

10:03 pm on Apr 23, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I think you'll have to inspect all the elements in that case (and for other browsers).

Can we have a bit more specific context info?

mennis

10:44 pm on Apr 23, 2004 (gmt 0)

10+ Year Member



Basically I'm trying to take a range from x,y,x2,y2 and looking for any and all objects contained within it. Even the objects on lower divs. In some cases I know the x,y,x2,y2 of the object, but there are several cases where I don't.

My current thought is on looking at every object on the page and building an array of the objects and their coordinates. I could then do a comparison against my original range.

So, I need to know if there is a way to look at the object in the div and to get it's true height and width to calculate the coordinates correctly. I have a situation with text where the user can set the div width wider than the actual text. So if I use the div for matching, it will match the div if the original range is wide enough, but not the text if you are outside the text width, but not the div.

I'm thinking I need something like offsetWidth. I have no problem understanding examples, I just don't have a lot of javascript experience to know all of the syntax and functions available. If you have any ideas on capturing the true coordinates, I think I can handle the rest. :)

Appreciate the help!

will1480

6:45 am on Apr 24, 2004 (gmt 0)

10+ Year Member



Im not sure I follow, but maybe this will help. if you have the id, and the width was set, use document.getElementById("the div boxes id").style.width