I was working on a project recently and the function had been implemented. Suddenly the user requested that the table header be floating (because the content is displayed on the same page and the column headers cannot be seen when scrolling). Since the function has been implemented using jquery pure html, in order to reduce changes, we can only use jquery original ecology to implement scrolling.
html header code:
< ;tr class="header" >
|
|
Faculty |
Scientific Research< ;/td>
| |
jquery code:
$(window).scroll(function(){
var headers = $(".header");//Get all header rows, the current one is 3 rows of headers
var yy = $(this).scrollTop();//Scroll bar top value
if(yy>55){
yy = yy-55;
}
var height1 = yy ;//The top value of the first line
var height2 = $(headers[0]).height() yy;//No. The top value of a row, the sum of the row height of the first row and the top value of the scroll bar
var height3 = $(headers[0]).height() $(headers[1]).height() yy;
$(headers[0]).css({"position":"absolute",top:height1 "px"});//Floating row
$(headers[1]).css( {"position":"absolute",top:height2 "px"});
$(headers[2]).css({"position":"absolute",top:height3 "px"});
[javascript] view plaincopy
$("#hiddenTd").height($(headers[0]).height() $(headers[1]).height() $( headers[2]).height());//As the header floats, the corresponding table content automatically moves up. In order to float the header The table content will not be overwritten, and a blank row will be set. The height will be the height of the table header
Note: When using multi-line headers, do not use the rowspan attribute in cells, otherwise the headers will be misaligned.