I have a fixed header scrolling table with horizontal and vertical scroll bars, for which I can presently sort on each column but am unable to properly preserve horizontal position of the table when loading the page.
Using the following inline css I get scrollAmount
from php from a hidden input whose value is from a jquery code and input it into the inline css
style="transform:translateX(<negative offset value of scrollAmount>)"
My question is how do I properly maintain scroll position for a table that overflows with a horizontal scroll bar using CSS and jQuery without waiting for the page to completely load / finish rendering?
Inline style
transform:translateX(-<?=scrollAmount()?>px)
jQuery Scroll Position Function
function setScroll(id_header, id_table)
{
$('div.'+id_table).on("scroll", function(){ //activate when #center scrolls
var left = $('div.'+ id_table).scrollLeft(); //save #center position to var left
$('div.'+id_header).scrollLeft(left); //set #top to var left
$('#scrollamount').val(left);
});
Hidden Input HTML Code
<input type="hidden" id="scrollamount" name="scrollamount" value=<?=scrollAmount()?>"/>
PHP Code
function scrollAmount()
{
if (isset($_POST['scrollamount']))
return $_POST['scrollamount'];
return "";
}