Table header to stay fixed at the top when user scrolls it out of view with jQuery

后端 未结 25 2149
悲&欢浪女
悲&欢浪女 2020-11-22 05:38

I am trying to design an HTML table where the header will stay at the top of the page when AND ONLY when the user scrolls it out of view. For example, the table may be 500

25条回答
  •  广开言路
    2020-11-22 06:17

    function fix_table_header_position(){
     var width_list = [];
     $("th").each(function(){
        width_list.push($(this).width());
     });
     $("tr:first").css("position", "absolute");
     $("tr:first").css("z-index", "1000");
     $("th, td").each(function(index){
        $(this).width(width_list[index]);
     });
    
     $("tr:first").after("");}
    

    This is my solution

提交回复
热议问题