冻结表格(tablefix)
来源:互联网 发布:沪港通每日交易数据 编辑:程序博客网 时间:2024/06/09 22:45
/*
* jQuery TableFix plugin ver 1.0.0
* Copyright (c) 2010 Otchy
* This source file is subject to the MIT license.
* http://www.otchy.net
*/
(function($){
$.fn.tablefix = function(options) {
return this.each(function(index){
// 処理継続の判定
var baseTable = $(this);
var withWidth = (options.width > 0);
var withHeight = (options.height > 0);
if (withWidth) {
withWidth = (options.width < baseTable.width());
} else {
options.width = baseTable.width();
}
if (withHeight) {
withHeight = (options.height < baseTable.height());
} else {
options.height = baseTable.height();
}
if (withWidth || withHeight) {
if (withWidth && withHeight) {
options.width -= 40;
options.height -= 40;
} else if (withWidth) {
options.width -= 20;
} else {
options.height -= 20;
}
} else {
return;
}
// 外部 div の設定
baseTable.wrap("<div></div>");
var div = baseTable.parent();
div.css({position: "relative"});
// スクロール部オフセットの取得
var fixRows = (options.fixRows > 0) ? options.fixRows : 0;
var fixCols = (options.fixCols > 0) ? options.fixCols : 0;
var offsetX = 0;
var offsetY = 0;
baseTable.find('tr').each(function(indexY) {
$(this).find('td,th').each(function(indexX){
if (indexY == fixRows && indexX == fixCols) {
var cell = $(this);
offsetX = cell.position().left;
offsetY = cell.parent('tr').position().top;
return false;
}
});
if (indexY == fixRows) {
return false;
}
});
// テーブルの分割と初期化
var crossTable = baseTable.wrap('<div></div>');
var rowTable = baseTable.clone().wrap('<div></div>');
var colTable = baseTable.clone().wrap('<div></div>');
var bodyTable = baseTable.clone().wrap('<div></div>');
var crossDiv = crossTable.parent().css({position: "absolute", overflow: "hidden"});
var rowDiv = rowTable.parent().css({position: "absolute", overflow: "hidden"});
var colDiv = colTable.parent().css({position: "absolute", overflow: "hidden"});
var bodyDiv = bodyTable.parent().css({position: "absolute", overflow: "auto"});
div.append(rowDiv).append(colDiv).append(bodyDiv);
// クリップ領域の設定
var bodyWidth = options.width - offsetX;
var bodyHeight = options.height - offsetY;
crossDiv.width(offsetX).height(offsetY);
rowDiv
.width(bodyWidth + (withWidth ? 20 : 0) + (withHeight ? 20 : 0))
.height(offsetY)
.css({left: offsetX + 'px'});
rowTable.css({
marginLeft: -offsetX + 'px',
marginRight: (withWidth ? 20 : 0) + (withHeight ? 20 : 0) + 'px'
});
colDiv
.width(offsetX)
.height(bodyHeight + (withWidth ? 20 : 0) + (withHeight ? 20 : 0))
.css({top: offsetY + 'px'});
colTable.css({
marginTop: -offsetY + 'px',
marginBottom: (withWidth ? 20 : 0) + (withHeight ? 20 : 0) + 'px'
});
bodyDiv
.width(bodyWidth + (withWidth ? 20 : 0) + (withHeight ? 20 : 0))
.height(bodyHeight + (withWidth ? 20 : 0) + (withHeight ? 20 : 0))
.css({left: offsetX + 'px', top: offsetY + 'px'});
bodyTable.css({
marginLeft: -offsetX + 'px',
marginTop: -offsetY + 'px',
marginRight: (withWidth ? 20 : 0) + 'px',
marginBottom: (withHeight ? 20 : 0) + 'px'
});
if (withHeight) {
rowTable.width(bodyTable.width());
}
// スクロール連動
bodyDiv.scroll(function() {
rowDiv.scrollLeft(bodyDiv.scrollLeft());
colDiv.scrollTop(bodyDiv.scrollTop());
});
// 外部 div の設定
div
.width(options.width + (withWidth ? 20 : 0) + (withHeight ? 20 : 0))
.height(options.height + (withWidth ? 20 : 0) + (withHeight ? 20 : 0));
});
}
})(jQuery);
* jQuery TableFix plugin ver 1.0.0
* Copyright (c) 2010 Otchy
* This source file is subject to the MIT license.
* http://www.otchy.net
*/
(function($){
$.fn.tablefix = function(options) {
return this.each(function(index){
// 処理継続の判定
var baseTable = $(this);
var withWidth = (options.width > 0);
var withHeight = (options.height > 0);
if (withWidth) {
withWidth = (options.width < baseTable.width());
} else {
options.width = baseTable.width();
}
if (withHeight) {
withHeight = (options.height < baseTable.height());
} else {
options.height = baseTable.height();
}
if (withWidth || withHeight) {
if (withWidth && withHeight) {
options.width -= 40;
options.height -= 40;
} else if (withWidth) {
options.width -= 20;
} else {
options.height -= 20;
}
} else {
return;
}
// 外部 div の設定
baseTable.wrap("<div></div>");
var div = baseTable.parent();
div.css({position: "relative"});
// スクロール部オフセットの取得
var fixRows = (options.fixRows > 0) ? options.fixRows : 0;
var fixCols = (options.fixCols > 0) ? options.fixCols : 0;
var offsetX = 0;
var offsetY = 0;
baseTable.find('tr').each(function(indexY) {
$(this).find('td,th').each(function(indexX){
if (indexY == fixRows && indexX == fixCols) {
var cell = $(this);
offsetX = cell.position().left;
offsetY = cell.parent('tr').position().top;
return false;
}
});
if (indexY == fixRows) {
return false;
}
});
// テーブルの分割と初期化
var crossTable = baseTable.wrap('<div></div>');
var rowTable = baseTable.clone().wrap('<div></div>');
var colTable = baseTable.clone().wrap('<div></div>');
var bodyTable = baseTable.clone().wrap('<div></div>');
var crossDiv = crossTable.parent().css({position: "absolute", overflow: "hidden"});
var rowDiv = rowTable.parent().css({position: "absolute", overflow: "hidden"});
var colDiv = colTable.parent().css({position: "absolute", overflow: "hidden"});
var bodyDiv = bodyTable.parent().css({position: "absolute", overflow: "auto"});
div.append(rowDiv).append(colDiv).append(bodyDiv);
// クリップ領域の設定
var bodyWidth = options.width - offsetX;
var bodyHeight = options.height - offsetY;
crossDiv.width(offsetX).height(offsetY);
rowDiv
.width(bodyWidth + (withWidth ? 20 : 0) + (withHeight ? 20 : 0))
.height(offsetY)
.css({left: offsetX + 'px'});
rowTable.css({
marginLeft: -offsetX + 'px',
marginRight: (withWidth ? 20 : 0) + (withHeight ? 20 : 0) + 'px'
});
colDiv
.width(offsetX)
.height(bodyHeight + (withWidth ? 20 : 0) + (withHeight ? 20 : 0))
.css({top: offsetY + 'px'});
colTable.css({
marginTop: -offsetY + 'px',
marginBottom: (withWidth ? 20 : 0) + (withHeight ? 20 : 0) + 'px'
});
bodyDiv
.width(bodyWidth + (withWidth ? 20 : 0) + (withHeight ? 20 : 0))
.height(bodyHeight + (withWidth ? 20 : 0) + (withHeight ? 20 : 0))
.css({left: offsetX + 'px', top: offsetY + 'px'});
bodyTable.css({
marginLeft: -offsetX + 'px',
marginTop: -offsetY + 'px',
marginRight: (withWidth ? 20 : 0) + 'px',
marginBottom: (withHeight ? 20 : 0) + 'px'
});
if (withHeight) {
rowTable.width(bodyTable.width());
}
// スクロール連動
bodyDiv.scroll(function() {
rowDiv.scrollLeft(bodyDiv.scrollLeft());
colDiv.scrollTop(bodyDiv.scrollTop());
});
// 外部 div の設定
div
.width(options.width + (withWidth ? 20 : 0) + (withHeight ? 20 : 0))
.height(options.height + (withWidth ? 20 : 0) + (withHeight ? 20 : 0));
});
}
})(jQuery);
- 冻结表格(tablefix)
- JS冻结表格
- JS冻结表格
- 表格列冻结
- 表格冻结第一行
- 模拟Excel冻结表格
- 前端#表格冻结
- jquery 表格冻结
- HTML表格冻结第一列
- 02-如何冻结拆分表格
- html+jquery 冻结表格表头
- jQuery实现表格冻结窗口
- jQuery实现表格冻结行和列
- 实现表格冻结顶栏效果
- html冻结表格——类似excel功能
- 关于表格冻结行和列的方法
- Ext实现表格列头冻结效果,锁定列头
- html中表格table冻结行和列
- ER图实例解析
- Linux设备模型之platform总线
- 细观排名 搜索引擎给以微薄不错权重
- 第五章 数组
- ibatis与hibernate结合使用(配置篇一)
- 冻结表格(tablefix)
- winform笔记
- Js控制css——模仿视频网站关灯开灯
- 实现文本域的maxlength
- [置顶]铁道部购票网站可能造成另一次的密码危机
- 网上订火车票的方法(Firefox+Firebug)
- extjs自定义事件
- 中国企业家:淘宝的艰难新生
- “今夜酒店特价”的商业模式是什么?