Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Mouse no longer in browser window

Status
Not open for further replies.

mattquantic

Programmer
Mar 28, 2004
196
GB
Hi. Is it possible to establish if the mouse is still within the confines of a browser window.

I have a dragable layer and it works fine with draging when the mouse is down and stopping whern the mouse is up.

But, if you keep the mouse down and then drag the mouse all of the way out of the window the layer move to the edge but when the mouse goes back within the window the system still thinks the mouse is down and keeps draging.

I have a script being called every 100ms. Can I put something in there to say if the mouse is no longer within the browser window to call the stop drag function?

M@)
 
You may need to trap an onmouseoff event as well.
I ran into this same problem a couple years back but do not recall the exact fix.

You do have to take into account the order of execution of events. Some events have higher priority over others and can effectively cancel out other event detections.

Also, if you can set your event detection to a higher level of the page you may avoid some problems.
For instance, if you click an object to drag it and you reach the edge of where that object can drag your mouse can still move to other areas of the screen. If however you use a mouseup event on the draggable object to cancel dragging that event will not fire because your mouse is not over the object so the event does not apply.
If the mouseup event was set on a higher level like the whole page then it would fire.

The best bet may be to set your events at a document level and when a click occurs then you test to see if the mouse is currently over the draggable object before executing the code to begin dragging. This way the event is trapped anywhere on the page but dragging only occurs if the mouse is in the correct location.


At my age I still learn something new every day, but I forget two others.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top