function $(id) { return document.getElementById(id)};
function moves(){
var ypos = $("movebox").style.left;//这里为什么获取不到呢  使用parseInt也不行 
alert(ypos);
if (ypos < 180) {
ypos++;
}


}
请指教 谢谢.

解决方案 »

  1.   

    我使用绝对定位,在样式里
    难道需要先用脚本给它设定positon吗
      

  2.   

    做滚动的话...
     一般是操作scroll
      

  3.   

    style.position为relation或absolute时才可以取到这个属性
      

  4.   

    谢谢楼上朋友的热心回复,我是想做个简单的动画效果,一个DIV在另外一个DIV里,从左到右移动
      

  5.   


     那个移动.  一般是操作外层的scroll来实现..   因为这样的话. 就不用管那个DIV里是什么东西了.
      

  6.   

    那就这样吧,一样的效果
    function $(id) { return document.getElementById(id)}; 
    function moves(){ 
    var ypos = $("movebox").offsetLeft;//这里为什么获取不到呢  使用parseInt也不行 
    alert(ypos); 
    if (ypos < 180) { 
    ypos++; 

    $("movebox").style.left=ypos+"px";}
      

  7.   


    <!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>无标题文档</title>
    <style>
    .box{border:#C90 1px solid;width:200px;height:20px; margin:0 auto; overflow:hidden;}
    .movebox{width:20px;height:20px; background:#9C0; overflow:hidden;}
    </style>
    </head><body onload="moves()">
    <div class="box">
    <div class="movebox" id="movebox"></div>
    </div><script>
    function $(id) { return document.getElementById(id)}; 
    function moves(){ 
    var ypos = $("movebox").offsetLeft; if (ypos < 180) { 
    ypos++; 

    $("movebox").style.left=ypos+"px";
    setTimeout(moves,100)}</script>
    </body>
    </html>
      

  8.   

    <body onload="moves()">这里不是在加载的时候执行了吗