问题是多次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>
解决方案 »
- 动态创建的元素无法设置name属性吗?
- baidu网页在框架页中的影响,,哪位高手可以消除这种影响??
- 求助,JS控制动态内容的问题
- easyui分页问题。大家帮个忙。
- 提交表单的小问题,如何在提交表单时弹出一个对话框,提示是否提交。
- 得到一对象,如何判断是什么类型的对象?如javascript对象,html对象?
- 能帮我找几本电子书吗?
- Ext:右键点击树节点,为什么两个判断都返回false呢
- 如何取消所有document对象的onmouseover事件呢,我是 说通过程序,我很着急谢谢
- 1.如何自动使输入框里输入的字母变为大写?2.如何使输入框只能输入数字?
- 请教各位怎样去掉<textarea>里的scrollbar
- 如何设置IE的安全级别,才允许JavaScript调用ActiveX的方法?
[email protected]