本人是个初学者,主要问题是这样的,网页上有一个div,我现在通过他的margin-top属性控制它的移动,移动已经实现了,主要是想实现在移动中的动态效果,而不是生硬的转换,感谢各位了……
实现移动的大概代码如下:
function turnPre(id,length)
{
  if (parseInt(document.getElementById(id).style.marginTop)==0)
  {
    return;
  }
    else
  {
    document.getElementById(id).style.marginTop = parseInt(document.getElementById(id).style.marginTop) + length;
  }
}

解决方案 »

  1.   

    照你的代码加的,我没测试过,意会下吧function turnPre(id,length) 

      if (parseInt(document.getElementById(id).style.marginTop)==0) 
      { 
        return; 
      } 
        else 
      { 
        document.getElementById(id).style.marginTop = parseInt(document.getElementById(id).style.marginTop) + length; 
      } 
    }
    function turnAni(id,length){
    var stepTop=1;//每次位移量
    var stepTime=100;//间隔毫秒
    for(int i=stepTop;i<length;i=i+stepTop){
    setTimeout("turnPre('"+id+"',"+i+")",stepTime);
    }
    }
      

  2.   

    不好意思 写的“手滑”了,js里没有int声明,改成varfunction turnAni(id,length){
        var stepTop=1;//每次位移量
        var stepTime=100;//间隔毫秒
        for(var i=stepTop;i<length;i=i+stepTop){
            setTimeout("turnPre('"+id+"',"+stepTop+")",stepTime);
        }
    }