Kor
10-15-2003, 10:57 AM
I have the following codes. I capture the mouse position, but I want to display the difference between the absolute X Y mouse position and another value. Now, if I use numbers, everything is ok, but If I use definite variables the result is NaN...??
Any ideea why this?
<html>
<head>
<script language="JavaScript" type="text/JavaScript">
function objectSetup(){
zDiv = new layerSetup("grafic",100,100,200,200);
}
function layerSetup(id,left,top,height,width){
if (document.getElementById){
this.obj = document.getElementById(id).style;
this.obj.left = left;
this.obj.top = top;
this.obj.height = height;
this.obj.width = width;
return this.obj;
} else if(document.all) {
this.obj = document.all[id].style;
this.obj.left = left;
this.obj.top = top;
this.obj.height = height;
this.obj.width = width;
return this.obj;
} else if(document.layers) {
this.obj = document.layers[id];
this.obj.left = left;
this.obj.top = top;
this.obj.height = height;
this.obj.width = width;
return this.obj;
}
}
function bla()
{
if (document.layer) {
document.captureEvents(Event.MOUSEMOVE);
}
document.onmousemove=showMousePosition;
}
function showMousePosition(e)
{
var mX, mY;
xDiv = zDiv.left;
yDiv = zDiv.top;
hDiv = zDiv.height;
wDiv = zDiv.width;
if (document.layer) {
mX = e.pageX;
mY = e.pageY;
}
else {
mX = window.event.clientX;
mY = window.event.clientY;
YY = mY - yDiv;
}
window.status = "X="+mX+" Y="+YY;
return true;
}
</script>
<style type="text/css">
<!--
#grafic {
background-color: #CCCCCC;
position: absolute;
}
-->
</style>
</head>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" onload="objectSetup();bla()">
<div id="grafic"></div>
</body>
</html>
Any ideea why this?
<html>
<head>
<script language="JavaScript" type="text/JavaScript">
function objectSetup(){
zDiv = new layerSetup("grafic",100,100,200,200);
}
function layerSetup(id,left,top,height,width){
if (document.getElementById){
this.obj = document.getElementById(id).style;
this.obj.left = left;
this.obj.top = top;
this.obj.height = height;
this.obj.width = width;
return this.obj;
} else if(document.all) {
this.obj = document.all[id].style;
this.obj.left = left;
this.obj.top = top;
this.obj.height = height;
this.obj.width = width;
return this.obj;
} else if(document.layers) {
this.obj = document.layers[id];
this.obj.left = left;
this.obj.top = top;
this.obj.height = height;
this.obj.width = width;
return this.obj;
}
}
function bla()
{
if (document.layer) {
document.captureEvents(Event.MOUSEMOVE);
}
document.onmousemove=showMousePosition;
}
function showMousePosition(e)
{
var mX, mY;
xDiv = zDiv.left;
yDiv = zDiv.top;
hDiv = zDiv.height;
wDiv = zDiv.width;
if (document.layer) {
mX = e.pageX;
mY = e.pageY;
}
else {
mX = window.event.clientX;
mY = window.event.clientY;
YY = mY - yDiv;
}
window.status = "X="+mX+" Y="+YY;
return true;
}
</script>
<style type="text/css">
<!--
#grafic {
background-color: #CCCCCC;
position: absolute;
}
-->
</style>
</head>
<body bgcolor="#FFFFFF" leftmargin="0" topmargin="0" onload="objectSetup();bla()">
<div id="grafic"></div>
</body>
</html>