forked from w3c/wptreport
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathsticky-headers.js
37 lines (36 loc) · 1.29 KB
/
sticky-headers.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// from http://css-tricks.com/persistent-headers/
(function ($) {
function updateTH () {
$(".persist-area").each(function() {
var $el = $(this)
, offset = $el.offset()
, scrollTop = $(window).scrollTop()
, $floatingHeader = $(".floatingHeader", this)
;
if ((scrollTop > offset.top) && (scrollTop < offset.top + $el.height()))
$floatingHeader.css({ "visibility": "visible" });
else
$floatingHeader.css({ "visibility": "hidden" });
});
}
$(function() {
var $clonedHeaderRow;
$(".persist-area").each(function() {
$clonedHeaderRow = $(".persist-header", this);
var widths = [];
$clonedHeaderRow.find("td, th").each(function () {
widths.push($(this).outerWidth());
});
$clonedHeaderRow
.before($clonedHeaderRow.clone())
.css("width", $clonedHeaderRow.width())
.addClass("floatingHeader");
$clonedHeaderRow.find("td, th").each(function () {
$(this).css("width", widths.shift());
});
});
$(window)
.scroll(updateTH)
.trigger("scroll");
});
}(jQuery));