<!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>
解决方案 »
- 我有一函数不执行$(this),$("table tr").mouseout( function(){aliert($(this).attr("backgro}
- 添加成功后的提示信息
- 谁有jquery 的教程 发个地址 谢谢
- 表单取值
- js动态下拉列表实现
- JS中如何写:把EXCEL保存到指定的路径!
- 请教如何 用JS获得gridview里指定单元格里label的值
- 如何让长字符串输出的时候自动换行呢?
- 请问哪里有象新浪一样两边图片随位置一起动的代码啊
- 请问怎么批量下载网页上用jplayer播放的音频mp3
- 超郁闷,IE8 RC1 不执行 alert ?
- 高分请教xsl+javascript问题
确实有难题待解决
先把这解决了,,你就是高人
http://topic.csdn.net/u/20090223/16/aaaed7b2-3808-4ad7-8224-5520575ae56a.html