Ver Mensaje Individual
  #3 (permalink)  
Antiguo 27/10/2008, 06:01
Avatar de Panino5001
Panino5001
Me alejo de Omelas
 
Fecha de Ingreso: mayo-2004
Ubicación: -34.637167,-58.462984
Mensajes: 5.148
Antigüedad: 20 años
Puntos: 834
Respuesta: Coordernadas en un div

Exacto lo que dice caricatos Sólo agrego que para Explorer es offsetX y offsetY, y que si la posición de la capa no es relativa (o absoluta -esto no lo probé-) puede producir resultados diferentes en algunos navegadores.:
Código PHP:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<
html xmlns="http://www.w3.org/1999/xhtml">
<
head>
<
meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<
title>Documento sin t&iacute;tulo</title>
<
script>
function 
addEvent(o,t,f){
    if(
o.addEventListener){
        
o.addEventListener(t,f,false);
    }else if(
o.attachEvent){
        var 
ff=function(){
            
f.call(o,window.event);
        }
        
o.attachEvent('on'+t,ff);
    }
}
function 
getPos(e){
e=|| window.event;
posX=e.layerX || e.offsetX;
posY=e.layerY || e.offsetY;
return {
x:posX,y:posY}
}
function 
inLog(e){
var 
t=getPos(e);
document.getElementById('log').innerHTML='x:'+t.x+', y:'+t.y;
}
onload=function(){
    
addEvent(document.getElementById('pp'),'mousemove',inLog);
}
</script>
</head>

<body><br />
<br />
<br />
<br />
<br />

<div id="pp" style="background-color:#F00; width:500px; height:500px; position:relative"></div>
<div id="log"></div>
</body>
</html>