我有两个简单的 div,其中一个包含在另一个中
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;
}
我想移动容器内的第一个内部 div
<div id = "cont" onmousemove = "moveDiv()">
<div id = "numero">
1
</div>
</div>
moveDiv 简单的地方
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";
}
该代码无法按我的意愿工作。鼠标所在的位置和内部 div (numero) 移动的位置之间存在很大的偏移。我还想限制容器 div 内的移动。一些帮助将不胜感激。
谢谢。