问题是多次click,timer就叠加了,要注意clearTimeout
<script language="javascript">
var timer=null;
function move()
{
clearTimeout(timer);
xa=window.event.clientX;
ya=window.event.clientY;
xb=Layer1.style.pixelLeft;
yb=Layer1.style.pixelTop;
x=xb;
if(xb<xa)
{
movelayer();
}
else
{
movelayer1();
}
}
function movelayer1()
{
if(x>=xa)
{
y=((ya-yb)*(x-xb))/(xa-xb)+yb;
Layer1.style.pixelLeft=x;
Layer1.style.pixelTop=y;
x--;
timer=setTimeout('movelayer1()',100);
}
}
function movelayer()
{
if(x<=xa)
{
y=((ya-yb)*(x-xb))/(xa-xb)+yb;
Layer1.style.pixelLeft=x;
Layer1.style.pixelTop=y;
x++;
timer=setTimeout('movelayer()',100);
}
}
</script>
<body onclick="move()">
<div id="Layer1" style="position:absolute; width:67px; height:41px; z-index:1; left: 360px; top: 230px">
<input name=i type=button onclick="javascript:location.href='mailto:[email protected]';" value="[email protected]"></div>
</body>
<script language="javascript">
var timer=null;
function move()
{
clearTimeout(timer);
xa=window.event.clientX;
ya=window.event.clientY;
xb=Layer1.style.pixelLeft;
yb=Layer1.style.pixelTop;
x=xb;
if(xb<xa)
{
movelayer();
}
else
{
movelayer1();
}
}
function movelayer1()
{
if(x>=xa)
{
y=((ya-yb)*(x-xb))/(xa-xb)+yb;
Layer1.style.pixelLeft=x;
Layer1.style.pixelTop=y;
x--;
timer=setTimeout('movelayer1()',100);
}
}
function movelayer()
{
if(x<=xa)
{
y=((ya-yb)*(x-xb))/(xa-xb)+yb;
Layer1.style.pixelLeft=x;
Layer1.style.pixelTop=y;
x++;
timer=setTimeout('movelayer()',100);
}
}
</script>
<body onclick="move()">
<div id="Layer1" style="position:absolute; width:67px; height:41px; z-index:1; left: 360px; top: 230px">
<input name=i type=button onclick="javascript:location.href='mailto:[email protected]';" value="[email protected]"></div>
</body>
[email protected]