站内搜索: 请输入搜索关键词

当前页面: 开发资料首页Javascript 专题JavaScript实现AJAX的拖动效果

JavaScript实现AJAX的拖动效果

摘要: JavaScript实现AJAX的拖动效果
<tr> <td>

<textarea class=fm cols=78 id=code1 rows=12> HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <head> drag layer <script language="javascript" defer> /*written by joelee@51js */ var tmpElement=null; var dragElement=null; var downX,downY,tmp_o_x,tmp_o_y; var refElement=null; var dragActive=0; var draging=0; function readyDrag(){ dragActive=1; if(event.srcElement.tagName!="DIV") return; dragElement=event.srcElement.parentNode; tmpElement=dragElement.cloneNode(true); tmpElement.style.filter="alpha(opacity=90)"; tmpElement.style.zIndex=2; dragElement.style.zIndex=1; tmpElement.style.position="absolute"; if(dragElement.parentNode.tagName!="BODY"){ dragElement.style.left=dragElement.offsetLeft+dragElement.parentNode.style.pixelLeft; dragElement.style.top=dragElement.offsetTop+dragElement.parentNode.style.pixelTop; } downX=event.clientX; downY=event.clientY; tmp_o_x=dragElement.style.pixelLeft; tmp_o_y=dragElement.style.pixelTop; tmpElement.style.visibility="hidden"; document.body.appendChild(tmpElement); document.onmousemove=startDrag; } document.onmouseup=endDrag; function startDrag(){ if(dragActive==1&&event.button==1&&dragElement!=null&&tmpElement!=null){ tmpElement.style.visibility="visible"; tmpElement.style.left=tmp_o_x+event.clientX-downX; tmpElement.style.top=tmp_o_y+event.clientY-downY; dragElement.style.backgroundColor="#CCCCCC"; document.body.style.cursor="move"; draging=1; } } function endDrag(){ if(dragActive==1&&tmpElement!=null){ if(draging==1){ dragElement.removeNode(true); draging=0; } tmpElement.style.filter="alpha(opacity=100)"; tmpElement.style.zIndex=1; document.body.style.cursor="default"; if(refElement!=null&&refElement.parentNode!=null&&refElement.parentNode.tagName!="BODY"){ tmpElement.style.width=refElement.parentNode.style.width; tmpElement.style.position=""; refElement.parentNode.insertBefore(tmpElement,refElement); } } dragElement=null; tmpElement=null; dragActive=0; } function readyInsert(){ if(dragActive==1){ var element=event.srcElement; if(element==dragElement)return; if(element.tagName!="DIV") return; if(element.className=="dragBar"||element.className=="textSheet"||element.className=="blankBar") element=element.parentNode; element.style.backgroundColor="#CCCCCC"; element.style.filter="alpha(opacity=50)"; refElement=element; } } function failInsert(){ var element=event.srcElement; if(element.tagName!="DIV") return; try{ if(element.className=="dragBar"||element.className=="textSheet"||element.className=="blankBar") element=element.parentNode; }catch(e){} element.style.filter="alpha(opacity=100)"; element.style.backgroundColor="#FFFFFF"; refElement=null; } document.onselectstart=function(){return false} </script> </head> <body>

Window
Content
Content
Content
Content
把层拖动到这儿
把层拖动到这儿
BBS
Content
Log
Content
Content
Content
Content
Worker
Content
Tools
Content
</body> </textarea>

<input onclick="runEx('code')" onfocus=this.blur() style="CURSOR: hand" type=button value=运行代码> <input name=Submit onclick=cycode(code1) onfocus=this.blur() style="CURSOR: hand; WIDTH: 95px" type=button value=复制到剪贴板> <input onclick=svcode(code1) onfocus=this.blur() style="CURSOR: hand" type=button value=另存代码> [Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行]

<textarea class=fm cols=78 id=code2 rows=12> <head> DRAG the DIV <script defer> /****JoeLee************E-MAIL:hktx@163.com****QQ:48293707*****11:09 2006-2-9******/ var draged=false; tdiv=null; function dragStart(){ ao=event.srcElement; if((ao.tagName=="TD")||(ao.tagName=="TR"))ao=ao.offsetParent; else return; draged=true; tdiv=document.createElement("div"); tdiv.innerHTML=ao.outerHTML; tdiv.style.display="block"; tdiv.style.position="absolute"; tdiv.style.filter="alpha(opacity=70)"; tdiv.style.cursor="move"; tdiv.style.width=ao.offsetWidth; tdiv.style.height=ao.offsetHeight; tdiv.style.top=getInfo(ao).top; tdiv.style.left=getInfo(ao).left; document.body.appendChild(tdiv); lastX=event.clientX; lastY=event.clientY; lastLeft=tdiv.style.left; lastTop=tdiv.style.top; try{ ao.dragDrop(); }catch(e){} } function draging(){//重要:判断MOUSE的位置 if(!draged)return; var tX=event.clientX; var tY=event.clientY; tdiv.style.left=parseInt(lastLeft)+tX-lastX; tdiv.style.top=parseInt(lastTop)+tY-lastY; for(var i=0;i=parentCell.left&&tX<=parentCell.right&&tY>=parentCell.top&&tY<=parentCell.bottom){ var subTables=parentTable.cells[i].getElementsByTagName("table"); if(subTables.length==0){ if(tX>=parentCell.left&&tX<=parentCell.right&&tY>=parentCell.top&&tY<=parentCell.bottom){ parentTable.cells[i].appendChild(ao); } break; } for(var j=0;j=subTable.left&&tX<=subTable.right&&tY>=subTable.top&&tY<=subTable.bottom){ parentTable.cells[i].insertBefore(ao,subTables[j]); break; }else{ parentTable.cells[i].appendChild(ao); } } } } } function dragEnd(){ if(!draged)return; draged=false; mm=ff(150,15); } function getInfo(o){//取得坐标 var to=new Object(); to.left=to.right=to.top=to.bottom=0; var twidth=o.offsetWidth; var theight=o.offsetHeight; while(o!=document.body){ to.left+=o.offsetLeft; to.top+=o.offsetTop; o=o.offsetParent; } to.right=to.left+twidth; to.bottom=to.top+theight; return to; } function ff(aa,ab){//从GOOGLE网站来,用于恢复位置 var ac=parseInt(getInfo(tdiv).left); var ad=parseInt(getInfo(tdiv).top); var ae=(ac-getInfo(ao).left)/ab; var af=(ad-getInfo(ao).top)/ab; return setInterval(function(){if(ab<1){ clearInterval(mm); tdiv.removeNode(true); ao=null; return } ab--; ac-=ae; ad-=af; tdiv.style.left=parseInt(ac)+"px"; tdiv.style.top=parseInt(ad)+"px" } ,aa/ab) } function inint(){//初始化 for(var i=0;iGMAIL</td> </tr> <tr> <td>暂时无法显示GMAIL内容</td> <tr> </table><table border=0 class="dragTable" cellspacing="0"> <tr> <td>新浪体育</td> </tr> <tr> <td>解剖威队独门利器FW28 2万转引擎匹配超级变速器颁奖:辛吉斯欣喜能以冠军起步 印度搭档创下纪录法新社前瞻冬奥短道速滑:中韩唱主角 美加施冷箭</td> <tr> </table><table border=0 class="dragTable" cellspacing="0"> <tr> <td>焦点</td> </tr> <tr> <td>京广线中断4小时20临客返汉晚点 中国新闻网-湖北分社 - 所有 235 相关报道 »哈马斯已有总理人选 解放日报报业集团 - 所有 489 相关报道 »陈水扁是两岸关系麻烦制造者 武汉晨报 - 所有 179 相关报道 »</td> <tr> </table> </td> <td width="25%"> <table border=0 class="dragTable" cellspacing="0"> <tr> <td>中关村在线</td> </tr> <tr> <td>新年行情速递 双敏板卡低价推荐 终于等到了,映泰6600GT一降降一百 罗技G15游戏键盘热力促销,代购价仅529元 </td> <tr> </table></td> <td width="25%"> <table border=0 class="dragTable" cellspacing="0"> <tr> <td>网易商业</td> </tr> <tr> <td>上海GDP增幅去年出现回落应对反倾销 中国鞋企联手对抗欧盟尹家绪操盘南方汽车 长安谋求曲线整体境外上市</td> <tr> </table> </td> </tr> </table> </body> </textarea>

<input onclick="runEx('code')" onfocus=this.blur() style="CURSOR: hand" type=button value=运行代码> <input name=Submit onclick=cycode(code2) onfocus=this.blur() style="CURSOR: hand; WIDTH: 95px" type=button value=复制到剪贴板> <input onclick=svcode(code2) onfocus=this.blur() style="CURSOR: hand" type=button value=另存代码> [Ctrl+A 全部选择 提示:你可先修改部分代码,再按运行]

</td> </tr> </table>
↑返回目录
前一篇: JS的package/import机制的考察提纲
后一篇: 最常用的10个javascript自定义函数