最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 科技 - 知识百科 - 正文

使表格的标题列可左右拉伸jquery插件封装_jquery

来源:动视网 责编:小采 时间:2020-11-27 21:29:13
文档

使表格的标题列可左右拉伸jquery插件封装_jquery

使表格的标题列可左右拉伸jquery插件封装_jquery:插件名称命名为:jquery.tableresize.js,代码如下: 代码如下: /* Writen by mlcactus, 2014-11-24 这是我封装的一个jquery插件,能够使table的各列可以左右拉伸,从而使宽度变小或变大 用法: 单个table:$(#table_id).table
推荐度:
导读使表格的标题列可左右拉伸jquery插件封装_jquery:插件名称命名为:jquery.tableresize.js,代码如下: 代码如下: /* Writen by mlcactus, 2014-11-24 这是我封装的一个jquery插件,能够使table的各列可以左右拉伸,从而使宽度变小或变大 用法: 单个table:$(#table_id).table


插件名称命名为:jquery.tableresize.js,代码如下:

代码如下:
/*
Writen by mlcactus, 2014-11-24
这是我封装的一个jquery插件,能够使table的各列可以左右拉伸,从而使宽度变小或变大
用法:
单个table:$("#table_id").tableresize();
页面所有table:$("table").tableresize();
*/
(function ($) {
$.fn.tableresize = function () {
var _document = $("body");
$(this).each(function () {
if (!$.tableresize) {
$.tableresize = {};
}
var _table = $(this);
//设定ID
var id = _table.attr("id") || "tableresize_" + (Math.random() * 100000).toFixed(0).toString();
var tr = _table.find("tr").first(), ths = tr.children(), _firstth = ths.first();
//设定临时变量存放对象
var cobjs = $.tableresize[id] = {};
cobjs._currentObj = null, cobjs._currentLeft = null;
ths.mousemove(function (e) {
var _this = $(this);
var left = _this.offset().left, top = _this.offset().top, width = _this.width(), height = _this.height(), right = left + width, bottom = top + height, clientX = e.clientX, clientY = e.clientY;
var leftside = !_firstth.is(_this) && Math.abs(left - clientX) <= 5, rightside = Math.abs(right - clientX) <= 5;
if (cobjs._currentLeft || clientY > top && clientY < bottom && (leftside || rightside)) {
_document.css("cursor", "e-resize");
if (!cobjs._currentLeft) {
if (leftside) {
cobjs._currentObj = _this.prev();
}
else {
cobjs._currentObj = _this;
}
}
}
else {
cobjs._currentObj = null;
}
});
ths.mouseout(function (e) {
if (!cobjs._currentLeft) {
cobjs._currentObj = null;
_document.css("cursor", "auto");
}
});
_document.mousedown(function (e) {
if (cobjs._currentObj) {
cobjs._currentLeft = e.clientX;
}
else {
cobjs._currentLeft = null;
}
});
_document.mouseup(function (e) {
if (cobjs._currentLeft) {
cobjs._currentObj.width(cobjs._currentObj.width() + (e.clientX - cobjs._currentLeft));
}
cobjs._currentObj = null;
cobjs._currentLeft = null;
_document.css("cursor", "auto");
});
});
};
})(jQuery);

页面代码为:

代码如下:








$(document).ready(function () {
//使两张table同时支持左右拉伸
$("table").tableresize();
});



表格1












ID名字年纪地址电话
22Name:44Age:23Address:47Phone:15
28Name:42Age:68Address:30Phone:50
29Name:63Age:48Address:90Phone:76


表格2









ID名字年纪地址电话
22Name:44Age:23Address:47Phone:15
28Name:42Age:68Address:30Phone:50



文档

使表格的标题列可左右拉伸jquery插件封装_jquery

使表格的标题列可左右拉伸jquery插件封装_jquery:插件名称命名为:jquery.tableresize.js,代码如下: 代码如下: /* Writen by mlcactus, 2014-11-24 这是我封装的一个jquery插件,能够使table的各列可以左右拉伸,从而使宽度变小或变大 用法: 单个table:$(#table_id).table
推荐度:
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top