Skip to content

Instantly share code, notes, and snippets.

@jimitit
Last active August 29, 2015 14:26
Show Gist options
  • Save jimitit/26dd03c8ed0571f993ea to your computer and use it in GitHub Desktop.
Save jimitit/26dd03c8ed0571f993ea to your computer and use it in GitHub Desktop.
Sticky column on horizontal scroll
var lastScrollLeft = 0;
$(window).scroll(function() {
var documentScrollLeft = $(document).scrollLeft();
if (lastScrollLeft != documentScrollLeft) {
//console.log('scroll x' + documentScrollLeft);
//For first column check below line: *:nth-child(1)
$('#tbl_newdashboard > tbody').find("tr > *:nth-child(1)").css({
'position' : 'relative',
'left': documentScrollLeft + 'px',
'background-color': 'white',
'display': 'table-cell',
'background-clip': 'padding-box'
});
lastScrollLeft = documentScrollLeft;
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment