日期:2014-05-16 浏览次数:20374 次
<html>
<head>
<title>能够自由拖动布局区域的网页</title>
<style type="text/css">
<!--
body{
font-size:12px;
font-family:Arial, Helvetica, sans-serif;
margin:0px; padding:0px;
/*background-color:#ffffd5;*/
background-color:#e6ffda;
}
.dragTable{
font-size:12px;
/*border:1px solid #003a82;*/
border:1px solid #206100;
margin-bottom:5px;
width:100%;
/*background-color:#cfe5ff;*/
background-color:#c9ffaf;
}
td{
padding:3px 2px 3px 2px;
vertical-align:top;
}
.dragTR{
cursor:move;
/*color:#FFFFFF;
background-color:#0073ff;*/
color:#ffff00;
background-color:#3cb500;
height:20px;
font-weight:bold;
font-size:14px;
font-family:Arial, Helvetica, sans-serif;
}
#parentTable{
border-collapse:collapse;
}
-->
</style>
<script language="javascript" defer="defer">
var Drag={
dragged:false,
ao:null,
tdiv:null,
dragStart:function(){
Drag.ao=event.srcElement;
if((Drag.ao.tagName=="TD")
------解决方案--------------------
(Drag.ao.tagName=="TR")){
Drag.ao=Drag.ao.offsetParent;
Drag.ao.style.zIndex=100;
}else
return;
Drag.dragged=true;
Drag.tdiv=document.createElement("div");
Drag.tdiv.innerHTML=Drag.ao.outerHTML;
Drag.ao.style.border="1px dashed red";
Drag.tdiv.style.display="block";
Drag.tdiv.style.position="absolute";
Drag.tdiv.style.filter="alpha(opacity=70)";
Drag.tdiv.style.cursor="move";
Drag.tdiv.style.border="1px solid #000000";
Drag.tdiv.style.width=Drag.ao.offsetWidth;
Drag.tdiv.style.height=Drag.ao.offsetHeight;
Drag.tdiv.style.top=Drag.getInfo(Drag.ao).top;
Drag.tdiv.style.left=Drag.getInfo(Drag.ao).left;
document.body.appendChild(Drag.tdiv);
Drag.lastX=event.clientX;
Drag.lastY=event.clientY;
Drag.lastLeft=Drag.tdiv.style.left;
Drag.lastTop=Drag.tdiv.style.top;
},
draging:function(){//判断MOUSE的位置
if(!Drag.dragged
------解决方案--------------------
Drag.ao==null)return;
var tX=event.clientX;
var tY=event.clientY;
Drag.tdiv.style.left=parseInt(Drag.lastLeft)+tX-Drag.lastX;
Drag.tdiv.style.top=parseInt(Drag.lastTop)+tY-Drag.lastY;
for(var i=0;i<parentTable.cells.length;i++){
var parentCell=Drag.getInfo(parentTable.cells[i]);
if(tX>=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&&am