一个大div套一个小div,让小div向上移动,实现动画效果,结果报错,大牛们看看。

cutemurphy 2011-08-17 07:03:17
一个大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>
...全文
604 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
cutemurphy 2011-08-18
  • 打赏
  • 举报
回复
写成行内。
KK3K2005 2011-08-18
  • 打赏
  • 举报
回复
<!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分钟 原因不写了 自己感受
cutemurphy 2011-08-18
  • 打赏
  • 举报
回复
up up up
cutemurphy 2011-08-18
  • 打赏
  • 举报
回复
追问 继续继续
cutemurphy 2011-08-18
  • 打赏
  • 举报
回复

s.style.marginTop取不到margin-top的值
。。。
有没比较统一 规范的取法?
zhang98722 2011-08-17
  • 打赏
  • 举报
回复
var st=parseInt(s.style.marginTop);
这个是错的
s.style.marginTop取不到margin-top的值
cutemurphy 2011-08-17
  • 打赏
  • 举报
回复
人呢 牛人呢

87,915

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧