java web可以拖动表格单元格大小的html,鼠标拖动改变表格大小
时间:2011-06-16 iteye heisetoufa
效果图:拖动带颜色位置上的竖杠,可以左右拖动表格宽度,上下宽度一起 改变
缺点:拖动点极其精确,想拖动一次要有耐心
再帖代码:
Html代码
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style>
.resizeDivClass
{
position:absolute;
background-color:gray;
width:1;
z-index:1;
left:1;
cursor:e-resize;
}
.td1 {
font-size: 12px;
white-space:nowrap;
overflow:hidden;
text-overflow:ellipsis;
color:#0000ff;
pos:expression (this.offsetLeft*1+this.offsetWidth*1+tab.offsetLeft);
}
</style>
<script language=javascript>
function MouseDownToResize(obj){
obj.mouseDownX=event.clientX;
objobj.pareneTdW=obj.parentElement.offsetWidth;
obj.pareneTableW=tab.offsetWidth;
obj.setCapture();
}
function MouseMoveToResize(obj){
if(!obj.mouseDownX) return false;
var newWidth=obj.pareneTdW*1+event.clientX*1-obj.mouseDownX;
if(newWidth>0)
{
obj.parentElement.style.width = newWidth;
tab.style.width=obj.pareneTableW*1+event.clientX*1- obj.mouseDownX;
for (var i=1; i<=tab.rows(0).cells.length;i++){
var obj = eval("mydiv"+i);
objobj.style.left = obj.parentElement.offsetLeft*1+obj.parentElement.offsetWidth*1+tab.off setLeft;//obj.parentElement.style.pos;
}
}
}
function MouseUpToResize(obj){
obj.releaseCapture();
obj.mouseDownX=0;
}
function init(){
var tempStr = "";
for (var i=1; i<=tab.rows(0).cells.length;i++){
tempStr = ''<div id="mydiv''+i+''" class="resizeDivClass" onmousedown="MouseDownToResize(this);" onmousemove="MouseMoveToResize(this);" onmouseup="MouseUpToResize (this);"></div>'';
tab.rows(0).cells(i-1).innerHTML = tab.rows(0).cells(i- 1).innerHTML+tempStr;
var obj = eval("mydiv"+i);
objobj.style.left = obj.parentElement.style.pos;
}
}
</script>
</head>
<body onload="init()">
<table id=tab STYLE="table-layout:fixed;" >
<tr bgcolor=cccccc >
<td valign=top class="td1" ><nobr>改变table的列宽度改 </nobr></td>
<td valign=top class="td1" ><nobr>改变table的列宽度改 </nobr></td>
<td valign=top class="td1" ><nobr>改变table的列宽度改 </nobr></td>
</tr>
<tr>
<td class="td1"><nobr>改变table的列宽度 </nobr></td>
<td class="td1"><nobr>改变table的列宽度 </nobr></td>
<td class="td1"><nobr>改变table的列宽度 </nobr></td>
</tr>
</table>
</body>
</html>
|