日期:2014-05-16  浏览次数:20308 次

为嘛我的图片不移动。。。。
<!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=gb2312 "   />
<title> 无标题文档 </title>
</head>

<body     onload= "initSoccerBall(); ">
<img   src= "20073315204866045.jpg "   width= "200 "   height= "150 "   id= "soccerBall "   />
</body>

<script   language= "javascript ">
function   initSoccerBall()
{
document.getElementById( "soccerBall ").animationTimer   =   setInterval( 'moveObject(document.getElementById( "soccerBall "),500,0,25) ',50);
}

function   moveObject(target,destinationLeft,destinationTop,maxSpeed)
{

var   currentLeft   =   parseInt(retrieveComputedStyle(target, "left "));
var   currentTop   =   parseInt(retrieveComputedStyle(target, "top "));
if(isNaN(currentLeft))
{
currentLeft   =   0;
}

if(isNaN(currentTop))
{
currentTop   =   0;
}

if(currentLeft   <   destinationLeft)
{
currentLeft   +=   maxSpeed;
if(currentLeft   >   destinationLeft)
{
currentLeft   =   destinationLeft;
}
}
else
{
currentLeft   -=   maxSpeed;
if   (currentLeft   <   destinationLeft)
{
currentLeft   =   destinationLeft;
}
}

if(currentTop   <   destinationTop)
{
currentTop   +=   maxSpeed;

if(currentTop   >   destinationTop)
{
currentTop   =   destinationTop;
}
}
else
{
currentTop   -=   maxSpeed
if(currentTop   <   destinationTop)
{
currentTop   =   destinationTop;
}
}

target.style.left   =   eval(currentLeft   +   "px ");
target.style.top   =   eval(currentTop   +   "px ");
if(currentLeft   ==   destinationLeft   &&   currentTop   ==   destinationTop)
{
clearInterval(target.animationTimer);
}
}

function   retrieveComputedStyle(target,position)
{
var   num   =   null;
if   (position   ==   "left ")
{
num   =   target.offsetLeft;
}
else
{
num   =   target.offsetTop;
}
return   num;
}


</script>
</html>



------解决方案--------------------
<!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=gb2312 " />
<title> 无标题文档 </title>
<script language= "javascript &