為什么代碼運(yùn)行時,left的值在不停的變化,求幫助
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>my運(yùn)動</title>
<!-- <link href="運(yùn)動.css" type="text/css" ?rel="stylesheet"/>
<script src="運(yùn)動.js" type="text/javascript"></script> -->
<style type="text/css">
*{?
margin:0;?
padding:0;
font-family:"宋體";
}
#myblock
{
width:200px;
height:200px;
background:#99CC33;
position:relative;
left:-200px;
top:0;
}
#myblock span
{
width:50px;
height:50px;
position:absolute;
left:200px;
top:150px;
background:#9900FF;
}
</style>
<script type="text/javascript">
function ?mouseOver(L){
var timer=null;
clearInterval(timer);
var adiv=document.getElementById("myblock");
timer= setInterval(function(){
var v=0;
if(adiv.offsetLeft>L){
v=-10;
}
else{
v=10;
}
if(adiv.offsetLeft==L){
clearInterval(timer);
}
else{
adiv.style.left=adiv.offsetLeft+v+'px';
}
},30);
}
</script>
</head>
<body>
<div id="myblock" ?onmouseover="mouseOver(0)" onmouseout="mouseOver(-200)" >
<span >一個</span>
</div>
</body>
</html>
2016-10-05
因為圖形本身也在跟著代碼變化著,圖形運(yùn)動代碼也就跟著運(yùn)動啦