关于js中div漂浮问题,我的div不动
<html><head><metacharset="utf-8"/><styletype="text/css">#ad{width:120px;height:120px;...
<html>
<head>
<meta charset="utf-8"/>
<style type="text/css">
#ad{width:120px;height:120px;background:red;position:relative;}
</style>
<script type="text/javascript">
var obj=null;
var x=10,y=10;
var id=null;
var dtop=false;
function init(){
obj=document.getElementById("ad");
obj.style.left=x;
obj.style.top=y;
id=setInterval(move,100);
}
function move(){
height=document.documentElement.clientHeight-obj.offsetHeight;
if(y >= height){
y = height;
dtop = true;
}
if(y<=10){
y = 10;
dtop = false;
}
if(dtop){
y -= 10;
}
else{
y += 10
}
obj.style.posTop=y;
}
</script>
</head>
<body onload="init()">
<div id="ad"></div>
</body>
</html> 展开
<head>
<meta charset="utf-8"/>
<style type="text/css">
#ad{width:120px;height:120px;background:red;position:relative;}
</style>
<script type="text/javascript">
var obj=null;
var x=10,y=10;
var id=null;
var dtop=false;
function init(){
obj=document.getElementById("ad");
obj.style.left=x;
obj.style.top=y;
id=setInterval(move,100);
}
function move(){
height=document.documentElement.clientHeight-obj.offsetHeight;
if(y >= height){
y = height;
dtop = true;
}
if(y<=10){
y = 10;
dtop = false;
}
if(dtop){
y -= 10;
}
else{
y += 10
}
obj.style.posTop=y;
}
</script>
</head>
<body onload="init()">
<div id="ad"></div>
</body>
</html> 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询