I have two simple divs, where one is contained inside an other
div#numero{
position:absolute;
background-color:#ff3324;
border-style: solid;
border-width: 2px;
width:30px;
height:30px;
font-family: "Lucida Grande", "Lucida Sans Unicode", "Lucida Sans", Geneva, Verdana, sans-serif;
font-size:1em;
line-height: 30px;
text-align:center;
margin-left:0;
margin-right:0;
};
div#cont{
position:relative;
border-style: solid;
border-width: 2px;
width:500px;
height:500px;
margin-left:auto;
margin-right:auto;
padding:0;
}
I want to move the first inner div inside the container
<div id = "cont" onmousemove = "moveDiv()">
<div id = "numero">
1
</div>
</div>
where the moveDiv is simply
function moveDiv()
{
var e = document.all["numero"]
x = window.event.clientX ;
y = window.event.clientY ;
e.style.left = x +"px";
e.style.top = y +"px";
}
The code does not work as I would like. There's a very big offset between the position where the mouse is and where the inner div (numero) gets moved. I'd also like to limit the movement inside the container div. Some help would be appreciated.
thanks.