I would like that <tr> with id="row" stays on top of page, when and only if I scroll page down and falls out of viewed page. If table heading is viewed on page, this table row it's on his place not on top of page. I have table:
<table id="table"> <thead> <tr> <th>heading of table</th> </tr> </thead> <tbody> <tr id="row"> <td colspan=3>Search box</td> </tr> <tr> <td>info</td> <td>info</td> <td>info</td> </tr> <tr> <td>info</td> <td>info</td> <td>info</td> </tr> <tr> <td>info</td> <td>info</td> <td>info</td> </tr> <tr> <td>info</td> <td>info</td> <td>info</td> </tr> </tbody> <table id="row-fixed"></table>
This is what i've done so far, but it's not working:
var tableOffset = $("#table").offset().top; var $header = $("#table > row").clone(); var $fixedHeader = $("#row-fixed").append($header); $(window).bind("scroll", function() { var offset = $(this).scrollTop(); if (offset >= tableOffset && $fixedHeader.is(":hidden")) { $fixedHeader.show(); } else if (offset < tableOffset) { $fixedHeader.hide(); } }); What should I change in this code, that would work for <tr id="row">
Here is a working case: http://jsfiddle.net/fj8wM/4489/