/*
 * 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)相关推荐

  1. php表格怎么让某一行不显示,怎么冻结表格某一行

    冻结表格某一行的方法:1.依次在菜单栏依次点击"视图"→"冻结窗格"→"冻结拆分窗格":2.在菜单栏点击"视图",并选择 ...

  2. html冻结表格——类似excel功能

    这是一个html,无论怎么拖,横向标题和竖向标题都被固定 这是html代码: <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transiti ...

  3. mysql冻结某一列_jQuery 实现冻结表格行和列

    1.创建多个div,div之间通过css实现层叠,每个div放置当前表格的克隆.例如:需要行冻结时,创建存放冻结行表格的div,通过设置z-index属性和position属性,让冻结行表格在数据表格 ...

  4. bootstrap 冻结表格,冻结表头

    需要的文件下载: bootstrap-table:https://github.com/wenzhixin/bootstrap-table bootstrap-table-fiex-column:ht ...

  5. php模拟表格冻结,PHPExcel冻结(锁定)表头的简单实现方法

    本文实例讲述了PHPExcel冻结(锁定)表头的简单实现方法.分享给大家供大家参考,具体如下: PHPExcel是一款功能比较强大的操作微软excel的PHP插件,在导出数据时为了方便查看,有时需要锁 ...

  6. html如何冻结字段,利用jQuery实现HTML 表格行列冻结

    摘要:行列冻结是处理表格非常常见的应用,我们都知道用excel可以很轻松的实现这一功能.但html编写的web网页表格中并没有冻结表格这一功能,那又要如何才能实现表格的 行 列 冻结呢? 行列冻结是处 ...

  7. 关于bootstrap-table冻结列生成多个冻结表头和表格主体的问题

    Write By Monkeyfly 以下内容均为原创,如需转载请注明出处. 前提 项目中有3个页面的表格使用到了 bootstrap-table 冻结列的功能 其中,某个表格要实现如下图所示的功能: ...

  8. Qt高仿Excel表格组件-支持冻结列、冻结行、内容自适应和合并单元格

    目录 一.概述 二.效果展示 三.实现思路 1.冻结行.冻结列 2.行高自适应 3.蚂蚁线 四.测试代码 1.添加表格数据 2.设置冻结行.列 3.行高.列宽 4.单元格背景色 5.单元格文字 6.其 ...

  9. html表格行列变化插件,利用jQuery实现HTML 表格行列冻结

    摘要:行列冻结是处理表格非常常见的应用,我们都知道用excel可以很轻松的实现这一功能.但html编写的web网页表格中并没有冻结表格这一功能,那又要如何才能实现表格的 行 列 冻结呢? 行列冻结是处 ...

最新文章

  1. es6+最佳入门实践(10)
  2. zigbee 频谱波段
  3. C# using static 声明
  4. 应用服务器——JBoss架构分析
  5. centOS 6 rpm安装MySQL小记
  6. 利用scons构建project
  7. 自动关机故障常见排除法
  8. docker nginx部署web应用_实战docker,编写Dockerfile定制tomcat镜像,实现web应用在线部署...
  9. cvSobel() 梯度和Sobel导数
  10. AI 诊断新算法,可提前十年查出老年痴呆症;济南酒店推行“人脸识别”,没带证件也可住店...
  11. Linux文件系统和磁盘分区
  12. 2013 腾讯实习生招聘 武汉 一面
  13. 命令行里打 cd 简直是浪费生命
  14. linux设置合上电脑,[转载]笔记本上装CentOS 7 设置合上盖子不休眠
  15. 互联网时代各行业都在快速更替,金融行业为什么即将成为下一个风口?
  16. J2ee学习流程(zz)
  17. 计算机网络如何促进幼儿教师专业发展,新学期计算机网络实训报告范文与新幼儿教师的述职报告合集.doc...
  18. 大数据平台安装实验: ZooKeeper、Kafka、Hadoop、Hbase、Hive、Scala、Spark、Storm
  19. 深入理解Python函数的9个黄金法则
  20. Postman发送一个请求

热门文章

  1. BitTorrent协议规范之torrent文件
  2. 解析code4app上自定义AlerView(开源学习)
  3. 媒体宣传的优势与重要性
  4. eclispe安装windowBuilder出错问题解决
  5. 快递查询接口种类及对接方法
  6. 我的博客搬家啦!!!
  7. 企业IM都有哪些?要如何选择?
  8. target table has x column(s) but the inserted data has y column(s), including z partition column(s
  9. pid算法(平衡车+风力摆)
  10. python 停止工作 scapy_python – Scapy安装问题.没有什么似乎实际上被安装?