定义一个3X3的表格,最中间的那个单元格存放内容,其余的单元格用来做改变大小的手柄(function($){
$.fn.TableResizer = function(handles) {
if(!handles) handles = "0123456789";
this.each(function() {
var tab = $(this);
$.each(tab.find(">tbody>tr>td"), function(i){
var handle = parseInt(handles.charAt(i));
if(handle==4) return;
$(this).mousedown(function(e){
var mouseDownX=e.clientX, mouseDownY=e.clientY;
var oPlaceholder = $("<div style='filter:alpha(opacity=0);opacity:0;z-index:1;background-color:red;"
+"width:5px;height:5px;position:absolute;margin:0;padding:0;cursor:"+$(this).css("cursor")
+";left:"+(e.clientX-2)+"px;top:"+(e.clientY-2)+"px'/>").appendTo("body");
var originWidth = tab.width(), originHeight = tab.height(), originPos = tab.position();
var fOnMove = function(e) {
if(!mouseDownX) return;
oPlaceholder.css({left:e.clientX-2, top:e.clientY-2});
var deltaX = e.clientX - mouseDownX, deltaY = e.clientY - mouseDownY, idx = handle;
if(idx==0)
tab.css({left:originPos.left+deltaX, width:originWidth-deltaX, top:originPos.top+deltaY, height:originHeight-deltaY});
else if(idx==1)
tab.css({top:originPos.top+deltaY, height:originHeight-deltaY});
else if(idx==2)
tab.css({width:originWidth+deltaX, top:originPos.top+deltaY, height:originHeight-deltaY});
else if(idx==3)
tab.css({left:originPos.left+deltaX, width:originWidth-deltaX});
else if(idx==5)
tab.width(originWidth+deltaX);
else if(idx==6)
tab.css({left:originPos.left+deltaX, width:originWidth-deltaX, height:originHeight+deltaY});
else if(idx==7)
tab.height(originHeight+deltaY);
else
tab.css({width:originWidth+deltaX, height:originHeight+deltaY});
return false;
}
var fOnUp = function() {
mouseDownX = null;
$(this).unbind("mousemove", fOnMove).unbind("mouseup", fOnUp);
oPlaceholder.remove();
}
$(document).mousemove(fOnMove).mouseup(fOnUp);
return false;
})
})
})
return this;
}
})(jQuery)
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>无标题文档</title>
<script src="jquery.js"></script>
<script src="jq.table.resizer.js"></script>
<script>
$(function(){
$("#t1").TableResizer();
});
</script>
</head>
<body>
<table id="t1" style="position:absolute;left:10px;top:50px;border-spacing:0px;border-spacing:expression(this.cellSpacing=0);width:100px" border="0">
<tr style="height:2px">
<td style="background-color:blue;width:2px;cursor:nw-resize"></td>
<td style="background-color:pink;cursor:n-resize"></td>
<td style="background-color:blue;width:2px;cursor:ne-resize"></td>
</tr>
<tr>
<td style="background-color:pink;cursor:w-resize"></td>
<td style="background-color:yellow">
Line1
Line2
</td>
<td style="background-color:pink;cursor:e-resize"></td>
</tr>
<tr style="height:2px">
<td style="background-color:blue;cursor:sw-resize"></td>
<td style="background-color:pink;cursor:s-resize"></td>
<td style="background-color:blue;cursor:se-resize"></td>
</tr>
</table>
</body>
</html>
?
详细解决方案
任意改变table的大小
热度:100 发布时间:2012-08-24 10:00:21.0
适用于chrome,firefox和ie8,其它版本未知?
?使用的例子:
相关解决方案
- 关于for循环中delete 跟 拼接sql delete table in ()的效率比较?
- table js排序,该如何处理
- jsp页面中加了<table>元素后,页面出现了一大片空白后才出现表格?解决方法
- jsp页面中加了<table>元素后,页面出现了一大片空缺后才出现表格
- Unknown table 'book' in field list
- VS2010 RDLC 报表 表(table) 分页的时候怎么显示表头
- table 点击td剔除整行
- 【误删除了表】SQL 小弟我不小心执行了 drop table 表
- 关于固定表头。(GridView,Table。),该如何解决
- Table 布局怎么改用CSS定位
- sql清空表数据用truncate table 表名处理,若表名是以数字开头,或者完全是数字,这句会报语法异常
- c# 网页采摘 TABLE
- sqltxet能不能这么写成"select *rowid from table"
- 大哥们救上命啊ArgumentException: 列“xxx”不属于表 Table
- 动态添加<table>遇到的有关问题
- table 细边框解决方法
- 要取TextBox里的值插入表, insert into table value(); 括号里应该如何写
- table 嵌套有关问题
- 在类名上这样写是啥[Table(Name = "Product")]解决方法
- html中<table>和<asp:Tabel>有什么不一样啊该如何解决
- da.Fill(ds, startRecord, maxRecords, "table"); 工作原理解决办法
- web TABLE,该如何处理
- JS预览 Table
- 怎么自动补充html中<table>中的宽度和高度
- 关于<table class="Text">
- 执行“Alter table“报出” Syntax error in field definition“异常
- 如何能不让GridView变成<table>
- <table align="center">中的align属性过期了?该如何处理
- HTML用在<table>上的cellpadding、cellspacing在css里对应的是什么解决方案
- 元素"tr"不能嵌套在元素"table"中,该怎么处理