<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml2/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>无标题文档</title>
<script type="text/javascript">
  document.onmousemove=picfloat;
  function inicial() {
  document.getElementById("pic").style.left="0px";
  document.getElementById("pic").style.top="0px";
  }
  var left, top;
  var speed=5;
  function picfloat(event) {
  var event=window.event||event;
  while(1) {
  left=document.getElementById("pic").style.left;
  top=document.getElementById("pic").style.top;
  t=setTimeout(follow(left,top),1);
  }
  }
  function follow(left,top) {
  if(parseInt(left)<=parseInt(event.clientX)) {
  document.getElementById("pic").style.left=(parseInt(left)+speed)+"px";
  } else {
  document.getElementById("pic").style.left=(parseInt(left)-speed)+"px";
  }
  if(parseInt(top)<=parseInt(event.clientY)) {
  document.getElementById("pic").style.top=(parseInt(top)+speed)+"px";
  } else {
  document.getElementById("pic").style.top=(parseInt(top)-speed)+"px";
  }
  }
</script>
<style type="text/css">
#pic {
  position:absolute;
}
</style>
</head><body onload="inicial()"><div>  
<img src="images/xmsx.gif" onmouseover="document.location.href='Apr1st.html'" id="pic"/>
</div>  </body>
</html>
这段代码 当鼠标不移动的时候 图片移动的就非常慢 应该如何解决呢

解决方案 »

  1.   

    while(1) {
      left=document.getElementById("pic").style.left;
      top=document.getElementById("pic").style.top;
      t=setTimeout(follow(left,top),1);
      }
    这种写法不慢才怪你设置一个setTimeout就行了,没必要while的
      

  2.   

    可是不用while鼠标不动 图片也不动了啊
      

  3.   

    <img style="position:absolute;" src="http://c.csdn.net/bbs/t/5/i/pic_logo.gif" id="img1" />    window.setInterval("move()", 100);
        var left = 0;
        var top = 0;
        function move() {
           document.getElementById("img1").style.left = left + "px";
           document.getElementById("img1").style.top = top + "px";
           left++;
           top++;
           }
      

  4.   

    在本地测试没问题 发布到IIS上就不动了是怎么回事呢