I am having some trouble understanding how to get a variable to work in my .onmouseup
event.
I have a .onmousemove
event that defines a local variable that is, for example the distance the mouse has moved since .onmousedown
. I want to use that information in a function that executes .onmouseup
, however, I can't get it there. Here are the relevant bits of code:
document.onmousedown = function(){
var mouseStart = [event.pageX,event.pageY];
document.onmousemove = function(){
var dist = Math.sqrt(Math.pow(event.pageY-mouseStart[1],2)+Math.pow(event.pageX-mouseStart[0],2));
document.onmouseup = function() {
global_function(dist);
document.onmousemove = null;
}
}
}
I don't understand why mouseStart
is accessible but I get the get the error that dist is undefined.
I have other variables that also need to be passed which cannot be redefined during .onmouseup
.