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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

mouse location

Status
Not open for further replies.

defrex

Programmer
Aug 22, 2001
83
CA
hi! lol, i know this might be a realy bumd question, but i'm used to flash, in wich this is posible. but, is there a way to find out where the mouse is? like x and y cords? or i guess it would be top and left for css. byt either way, is there? not knowing is an excuse for those umwilling to lern -- John Rueben
 
Yeah there is a way to find out where the mouse is on the screen -- but its vastly different across browsers. Unfortionately, Netscape 6+, Mozilla, or anything else running gecko is the only browser to support the W3C DOM2 Event Model -- so that is bad. =(.

You have to capture the events, the code would be something like:


function capEvent(e){
if (document.all){
var xpos = event.clientX
var ypos = event.clientY
}
else if (document.sidebar || document.layers){
var xpos = e.clientX
var ypos = e.clientY
}
}

It might not be clientX and clientY -- could be screenX or screenY, don't quite remember right now. Hope that helps.

===
Supports Mozilla and Web Standards
Knows HTML/XHTML, CSS1, JavaScript, PHP, C++, DOM1
===
 
sorry, i'm a bit new to this. what is/dose event do? and what value should i give to e? again, i'm just starting to learn this stuff so i don't know much... not knowing is an excuse for those umwilling to lern -- John Rueben
 
event, or e, is the event object. It captures the event as it happens and saves information about the event.

event.type, or e.type, would tell you what type of event it is, such as onclick or onmouseover, etc.

event.clientY, e.clientY tells you the position on the screen the event happened. ===
Supports Mozilla and Web Standards
Knows HTML/XHTML, CSS1, JavaScript, PHP, C++, DOM1
===
 
So to find out where the mouse is and put it in the status bar, you coudl say something like:

function capEvent(e){

var xpos = e.clientX;
var ypos = e.clientY;

window.status = xpos + " " + ypos;

}

onmousemove = capEvent;
===
Supports Mozilla and Web Standards
Knows HTML/XHTML, CSS1, JavaScript, PHP, C++, DOM1
===
 
ok, that makes sence. thanx alot! not knowing is an excuse for those umwilling to lern -- John Rueben
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top