Created
November 2, 2012 23:24
-
-
Save jhthorsen/4004996 to your computer and use it in GitHub Desktop.
Fixed table header
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function($) { | |
$.fn.fixedHeader = function() { | |
this.each(function() { | |
var $table = $(this); | |
var $dummy = $('<table><tr></tr></table>'); | |
var $th = $table.find('thead:first tr:first th').clone(); | |
var $td = $table.find('tbody:first tr:first td'); | |
var place = function() { | |
$dummy.css({ | |
top: $table.offset().top, | |
left: $table.offset().left, | |
width: $table.width() | |
}); | |
$th.each(function(n, e) { | |
$(e).width($td.eq(n).width()); | |
}); | |
}; | |
$dummy | |
.attr('class', $table.attr('class')) | |
.removeClass('table-with-fixed-header') | |
.addClass('table-fixed-header') | |
.find('tr') | |
.append($th) | |
; | |
$('body').append($dummy); | |
$(window).resize(function() { place(); }).resize(); | |
}); | |
}; | |
})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment