求大神幫我看下這代碼,鼠標(biāo)離開(kāi)的時(shí)候,div不會(huì)回去呀?是什么問(wèn)題?
<!DOCTYPE html>
<html >
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>Js動(dòng)畫(huà)</title>
<style type="text/css">
<style>
*{margin:0;padding:0;}
#div1{
width:200px;
height:200px;
background:red;
position:relative;
left:-200px;
top:0;
}
#div1 span{
height: 50px;
position: absolute;
background:blue;
width: 20px;
left: 200px;
top: 75px;
}
</style>
</head>
<script type="text/javascript">
window.onload=function(){
var oDiv=document.getElementById('div1');
oDiv.onmouseover=function(){
startMove(0);
}
oDiv.onmouseout=function(){
startMove(-200);
}
}
var timer=null;
function startMove(iTarget){
clearInterval(timer);
var oDiv=document.getElementById('div1');
timer=setInterval(function(){
var speed= 0;
if (oDiv.offsetLeft>iTarget) {
speed==-10;
}else{
speed==10;
}
if(oDiv.offsetLeft==iTarget){
clearInterval(timer);
? ?}
else{
oDiv.style.left=oDiv.offsetLeft+speed+'px';
? ? ? }
? ? ? },30)
}
</script>
<body>
<div id="div1">
<span id="share">分享</span>
</div>
</html>
2015-09-14
if (oDiv.offsetLeft>iTarget) {
speed==-10;
}else{
speed==10;
}
自動(dòng)空行了? ,把這兩行代碼的==換成 =就行了
2015-09-11
88行 和 92行 不是等于 是賦值