jQuery插件修复滚动时 表头 floatThead

  • 源码大小:46.11KB
  • 所需积分:1积分
  • 源码编号:19JP-3146
  • 浏览次数:781次
  • 最后更新:2023年05月10日
  • 所属栏目:表格
本站默认解压密码:19jp.com 或 19jp_com

简介

floatThead是一个jQuery粘性表头插件,可以冻结您的表剧院滚动时位于页面/容器顶部的元素。

适用于窗口/容器/响应滚动。

兼容大多数流行的框架和JS库,如Bootstrap、jQueryUI、datatables、perfectScrollbar等。

想要有粘性的表列吗?看看stickyColumn插件,它是floatThead插件的扩展,当你垂直或水平滚动页面时,它使表的第ad列和前n列始终可见(粘性)。

安装:

  1. # NPM
  2. $ npm install floatthead
  3.  
  4. # Bower
  5. $ bower install floatthead

基本用法:

1.包含JavaScript文件jquery.floattad.js查询在jQuery库和floatThead准备好使用之后。

  1. <script src="//code.jquery.com/jquery.min.js"></script>
  2. <script src="dist/jquery.floatThead.js"></script>

2.请注意,您的html表必须具有剧院元素:

  1. <table>
  2. <thead>
  3. <tr>
  4. <th>Month</th>
  5. <th>Savings</th>
  6. </tr>
  7. </thead>
  8. <tfoot>
  9. <tr>
  10. <td>Sum</td>
  11. <td>$180</td>
  12. </tr>
  13. </tfoot>
  14. <tbody>
  15. <tr>
  16. <td>January</td>
  17. <td>$100</td>
  18. </tr>
  19. <tr>
  20. <td>February</td>
  21. <td>$80</td>
  22. </tr>
  23. </tbody>
  24. </table>

3.调用html表格上的函数会使表格标题在窗口滚动时具有粘性。

  1. $('table').floatThead();

4.滚动时,使表头在其父容器的顶部具有粘性。

  1. $('table').floatThead({
  2. scrollContainer: function($table){
  3. return $table.closest('.tableContainer');
  4. }
  5. });

5.所有默认的插件选项,用于自定义粘性表头。

  1. $('table').floatThead({
  2.  
  3. // thead cells
  4. headerCellSelector: 'tr:visible:first>*:visible',
  5.  
  6. // zindex of the floating thead (actually a container div)
  7. zIndex: 1001,
  8.  
  9. // 'fixed', 'absolute', 'auto'. auto picks the best for your table scrolling type.
  10. position: 'auto',
  11.  
  12. // offset from top of window where the header should not pass above
  13. top: 0,
  14.  
  15. // offset from the bottom of the table where the header should stop scrolling
  16. bottom: 0,
  17.  
  18. // or boolean 'true' (use offsetParent) | function -> if the table has horizontal scroll bars then this is the container that has overflow:auto and causes those scroll bars
  19. scrollContainer: function($table) {
  20. return $([]);
  21. },
  22.  
  23. // only valid if scrollContainer is not used (ie window scrolling). this is the container which will control y scrolling at some mobile breakpoints
  24. responsiveContainer: function($table) {
  25. return $([]);
  26. },
  27.  
  28. // this is only called when using IE,
  29. // override it if the first row of the table is going to contain colgroups (any cell spans greater than one col)
  30. // it should return a jquery object containing a wrapped set of table cells comprising a row that contains no col spans and is visible
  31. getSizingRow: function($table, $cols, $fthCells){
  32. return $table.find('tbody tr:visible:first>*:visible');
  33. },
  34.  
  35. // default CSS classes
  36. floatTableClass: 'floatThead-table',
  37. floatWrapperClass: 'floatThead-wrapper',
  38. floatContainerClass: 'floatThead-container',
  39.  
  40. // copy 'class' attribute from table into the floated table so that the styles match.
  41. copyTableClass: true,
  42.  
  43. // use MutationObserver api to reflow automatically when internal table DOM changes
  44. autoReflow: false,
  45.  
  46. // debug mode
  47. debug: false,
  48.  
  49. // should we bind events that expect these frameworks to be present and/or check for them?
  50. support: {
  51. bootstrap: true,
  52. datatables: true,
  53. jqueryUI: true,
  54. perfectScrollbar: true
  55. }
  56. });

更新日志:

v2.2.5版本(2023-03-11)

  • 错误修复

v2.2.4 (2021-09-02)

  • 更新的程序包

第2.2.3节(2021-08-20)

  • 错误修复

第2.2.2版(2021-08-18)

  • 修复了在浏览表时屏幕阅读器正确读取aria标签的问题。
  • 修复jQuery 3+警告

v2.2.1版本(2020-06-02)

  • 修复对多个表使用autoReflow时的销毁功能

v2.2.0版本(2020-05-29)

  • 修复对多个表使用autoReflow时的销毁功能
  • 支持具有现有colgroup的表中的隐藏列
  • TypeScript定义

v2.1.4版本(2019-08-02)

  • 在配置对象中添加了ariaLabel函数,使插件使用的值更加灵活
  • 改进RTL支持。
  • Aria标签不适用于引号。

v2.1.3版本(2019-01-16)

  • 错误修复

v2.1.2版本(2018年4月17日)

  • 使现代化

v2.1.1版本(2018年02月21日)

  • 如果在同一页面上的多个表上使用插件,则会大大提高性能。在一个有39个表的页面上,启动时间快了10倍以上
  • 添加“floatContainerOverflow”选项来管理floatContainer CSS
  • 修复firefox上的打印
  • 回流时设置页眉大小
  • 在iPad Retina上效果更好

v2.0.3版本(2018-01-26)

  • 回流时设置页眉大小

2017-06-02

  • 修复了util/isFunction错误

 

预览截图