-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstaticHeader.js
More file actions
68 lines (59 loc) · 1.79 KB
/
Copy pathstaticHeader.js
File metadata and controls
68 lines (59 loc) · 1.79 KB
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
// Purpose: For serving static headers to table headers
// By: Matt McAlear
// Date: 7/26/13
function makeStaticHeader(elementID){
this._element = document.getElementById(elementID);
this._jElement = $('#'+elementID);
this._doc = $(document);
this._header = document.getElementById('staticHead');
}
makeStaticHeader.prototype = {
//restore constructor
constructor: makeStaticHeader,
init: function(){
that = this;
window.onscroll = function(){
if(that._doc.scrollTop() >= that._jElement.position().top){
that._header.style.display = 'block';
}else{
that._header.style.display = 'none';
}
$('#staticHead').css({
'top': $(this).scrollTop()
});
};
},
makeHeader: function(){
that = this;
var w = this._element.offsetWidth;
var body=document.getElementsByTagName('body')[0];
var table=document.createElement('table');
table.style.width=w+'px';
table.style.position='absolute';
table.style.top='0px';
table.style.display='none';
table.style.opacity=.75;
table.style.backgroundColor='#888';
table.style.color='white';
table.style.overflowX='auto';
table.setAttribute('border','1');
table.setAttribute('id', 'staticHead');
var tbody=document.createElement('tbody');
var tr = this._element.cloneNode(true);
tr.style.width=w+'px';
var total = 0;
for(var i=0; i<this._element.cells.length; i++){
var pad;
if(i==0 || (i+1==this._element.cells.length)){ pad=2; }else{ pad = 4; }
tr.cells[i].style.width=(this._element.cells[i].offsetWidth-pad)+'px';
}
//Set elements
tbody.appendChild(tr);
table.appendChild(tbody);
body.appendChild(table);
//Set new static header
that._header = document.getElementById('staticHead');
//init listener
that.init();
}
}