新人求解,关于定时器,我是做一个分享栏,鼠标移入移出的
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.<html xmlns="http://www.
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>分享栏</title>
<style>
#div1 { width:100px;height:400px;background:yellow; position:absolute;left:-100px;}
#div1 span { position:absolute; width:20px;height:60; line-height:20px; background:blue;right:-20px;top:170px;}
</style>
<script type="text/javascript">
window.onload=function()
{
var oDiv=document.getElementById('div1');
oDiv.onmouseover=function()
{
move(0,10);
};
oDiv.onmouseout=function()
{
move(-100,-10);
};
//如果 var timer=null; 放在这一行,Div 就不会跳,求解,很疑惑
function move(posi,speed)
{
var timer=null ; //这行放在这里的话,会在第一次鼠标移出的时候,Div就会反复的跳,而且,在这以后,都会跳
clearInterval(timer);
timer=setInterval(function()
{
if(oDiv.offsetLeft==posi)
{ clearInterval(timer);}
else{ oDiv.style.left=oDiv.offsetLeft+speed+'px';}
},30);
};
};
</script>
</head>
<body>
<div id="div1">
<span id="sp">分享到</span>
</div>
</ul>
</body>
</html>