V
vunet.us
Hello,
My function gets mouse coordinates like this:
function getMouseCoords(e){
e = (e) ? e : window.event;
var x = 0;
var y = 0;
if(e.pageX){
x = e.pageX;
y = e.pageY;
}else if(e.clientX){
x = e.clientX + document.body.scrollLeft - document.body.clientLeft;
y = e.clientY + document.body.scrollTop - document.body.clientTop;
}
return new Array(x, y);
}
To run the function I pass event to it:
obj.onclick = runMe;
function runMe(ev){
ev = ev || window.event;
var mousecoords = getMouseCoords(ev);
}
Question: how to simulate or avoid using "ev" variable in runMe() but
get mouse coordinates anyway? I simply want to run runMe() in many
places and subroutines, so passing event seems to be a complicated
task.
Thanks
My function gets mouse coordinates like this:
function getMouseCoords(e){
e = (e) ? e : window.event;
var x = 0;
var y = 0;
if(e.pageX){
x = e.pageX;
y = e.pageY;
}else if(e.clientX){
x = e.clientX + document.body.scrollLeft - document.body.clientLeft;
y = e.clientY + document.body.scrollTop - document.body.clientTop;
}
return new Array(x, y);
}
To run the function I pass event to it:
obj.onclick = runMe;
function runMe(ev){
ev = ev || window.event;
var mousecoords = getMouseCoords(ev);
}
Question: how to simulate or avoid using "ev" variable in runMe() but
get mouse coordinates anyway? I simply want to run runMe() in many
places and subroutines, so passing event seems to be a complicated
task.
Thanks