一个大div套一个小div,让小div向上移动,实现动画效果,结果报错,大牛们看看。<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <title> New Document </title>
  <meta name="Generator" content="EditPlus">
  <meta name="Author" content="">
  <meta name="Keywords" content="">
  <meta name="Description" content="">
<style type="text/css">
#f{width:200px;height:200px;border:1px solid;margin-top:120px;}
#s{width:100px;height:100px;border:1px solid;margin-top:0px;}
</style>
 </head> <body>
  <div id="f">
  <div id="s">
  32132
  </div>
  </div>
  <script type="text/javascript">
var s=document.getElementById("s");
        var st=parseInt(s.style.marginTop);
 function mo(  ){
st-=10;
s.style.marginTop=st+"px";
 }
 setInterval("mo(  )",1000);
  </script>
 </body>
</html>

解决方案 »

  1.   

    var st=parseInt(s.style.marginTop);
    这个是错的
    s.style.marginTop取不到margin-top的值
      

  2.   


    s.style.marginTop取不到margin-top的值

    有没比较统一 规范的取法?
      

  3.   

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
     <head>
      <title> New Document </title>
      <meta name="Generator" content="EditPlus">
      <meta name="Author" content="">
      <meta name="Keywords" content="">
      <meta name="Description" content="">
    <style type="text/css">
    #f{width:200px;height:200px;border:1px solid;margin-top:120px;}
    #s{width:100px;height:100px;border:1px solid;margin-top:0px;}
    </style>
     </head> <body>
      <div id="f">
      <div id="s" style='margin-top:10px;'>
      32132
      </div>
      </div>
      <script type="text/javascript">
    var s=document.getElementById("s");
    var st=parseInt(s.style.marginTop);
    function mo( ){
    st-=10;
    s.style.marginTop=st+"px";
    }
    setInterval("mo( )",1000);
      </script>
     </body>
    </html>
    解决花费3分钟 原因不写了 自己感受