<!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" lang="zh-CN">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>两个div</title>
</head><body>
<div style="position: absolute; width: 100px; height: 100px; z-index: 3; left:10px; top:50px;border:1px #f00 solid" id="d1" >d1<br><br><span onclick="startMov()" id=inf style="color:red;font-weight:900;CURSOR: pointer">请点击:开始</span>
</div>
<div style="position: absolute; width: 100px; height: 100px; z-index: 1; left:10px; top:200px;border:1px #00f solid" id="d2">d2
</div><script language="javascript">
<!--
var obj1=$("d1"),obj2=$("d2"),T01=obj1.offsetTop,time=1;
var h1=obj1.offsetHeight,h2=obj2.offsetHeight;
function mov(){
var t1=obj1.offsetTop
var t2=obj2.offsetTop
// alert(t1+"\n"+t2) obj1.style.top=t1+1+"px"
if ((t1+h1)==t2){
alert("d1 光临 d2");
obj1.style.borderWidth="2px"
obj2.style.background="#aaf"
}
if ((t1)==t2+h2-2){
alert("d1 告别 d2")
obj1.style.borderWidth="1px"
obj2.style.background=""
}
if ((t1)==t2+h2+50){
alert("再见")
$("inf").innerHTML="请点击:返回"
time=0
}
else {setTimeout(mov,30)}
}
function startMov(){
if (time==1){$("inf").innerHTML="";mov()}
else {obj1.style.top=T01+"px";$("inf").innerHTML="请点击:开始";time=1}
}
function $(id){return document.getElementById(id)}
//-->
</script>
</body></html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="zh-CN">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>两个div</title>
</head><body>
<div style="position: absolute; width: 100px; height: 100px; z-index: 3; left:10px; top:50px;border:1px #f00 solid" id="d1" >d1<br><br><span onclick="startMov()" id=inf style="color:red;font-weight:900;CURSOR: pointer">请点击:开始</span>
</div>
<div style="position: absolute; width: 100px; height: 100px; z-index: 1; left:10px; top:200px;border:1px #00f solid" id="d2">d2
</div><script language="javascript">
<!--
var obj1=$("d1"),obj2=$("d2"),T01=obj1.offsetTop,time=1;
var h1=obj1.offsetHeight,h2=obj2.offsetHeight;
function mov(){
var t1=obj1.offsetTop
var t2=obj2.offsetTop
// alert(t1+"\n"+t2) obj1.style.top=t1+1+"px"
if ((t1+h1)==t2){
alert("d1 光临 d2");
obj1.style.borderWidth="2px"
obj2.style.background="#aaf"
}
if ((t1)==t2+h2-2){
alert("d1 告别 d2")
obj1.style.borderWidth="1px"
obj2.style.background=""
}
if ((t1)==t2+h2+50){
alert("再见")
$("inf").innerHTML="请点击:返回"
time=0
}
else {setTimeout(mov,30)}
}
function startMov(){
if (time==1){$("inf").innerHTML="";mov()}
else {obj1.style.top=T01+"px";$("inf").innerHTML="请点击:开始";time=1}
}
function $(id){return document.getElementById(id)}
//-->
</script>
</body></html>
解决方案 »
- 两个function 一个倒计时,一个执行. 胡搅的事
- 带有Activex控件的Web项目算不算是B/S模式?
- 我使用的您编写的树形控件1.0,怎么实现点开一个节点,其它的展开节点关闭的功能啊
- 为Hidden赋值,弹出消息提示框的问题~问题解决满分送上!!
- 文本框的植是javascript写进去的 怎么在不碰他的情况去触发他的时间 什么事件都行
- js:代参函数A作为参数传递时,A参数怎么办
- 客户端是ie6能够用网页的activx来修改注册表吗?
- 请问谁知道一个查询按钮怎样避免被重复点击?就是为了避免用户频繁点击查询,等待高手!
- 如何把 2|4|5|7 转化为一个数组,求出他们的和?
- 如何进行客户端组件编程?
- 超郁闷,IE8 RC1 不执行 alert ?
- 高分请教xsl+javascript问题
确实有难题待解决
先把这解决了,,你就是高人
http://topic.csdn.net/u/20090223/16/aaaed7b2-3808-4ad7-8224-5520575ae56a.html