var thead_top = ''
$(window).scroll(function() {
//计算 table 与顶部的距离
thead_top = $('#table').offset().top;
//计算滚动的距离
var top = parseFloat($(this).scrollTop())
let value = parseFloat($(this).scrollTop()) - thead_top - 1;
if(top > thead_top){
$('#table thead').css({
'transform':'translateY('+ value +'px)',
'background-color':'#12ca50'
});
}else{
$('#table thead').css({
'transform':'translateY(0px)',
'background-color':'#fff'
});
}
})
table 表头固定
最新推荐文章于 2024-07-25 21:26:56 发布