Make table header fixed when scrolling

后端 未结 1 1781
死守一世寂寞
死守一世寂寞 2021-01-06 06:20

I am using Bootstrap V4 alpha 6 along with Angular 5 to create a table with a fixed header when scrolling. However, I can\'t seem to get it to work

1条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-06 07:00

    The easiest way to achieve this is to create your own JavaScript function to manipulate the behavior as required. Play around with the following snippet code to meet your expectations.

    document.onscroll = function() {
      var scroll = $(window).scrollTop();
      if (scroll >= 50) {
        $("thead").css({
          "position": "fixed",
          "top": "0px"
        });
        $("th").css({"padding":"15px 66px", "margin":"auto"});
      } else {
        $("thead").css({
          "position": "relative",
          "top": "0px"
        });
      }
    };
    
    
    
    Full Name Gender Country
    Sam Tomashi Male D.R.Congo
    Molly Akinyi Female Kenya
    John Doe Male France
    Sam Tomashi Male D.R.Congo
    Molly Akinyi Female Kenya
    John Doe Male France
    Sam Tomashi Male D.R.Congo
    Molly Akinyi Female Kenya
    John Doe Male France
    Sam Tomashi Male D.R.Congo
    Molly Akinyi Female Kenya
    John Doe Male France
    Sam Tomashi Male D.R.Congo
    Molly Akinyi Female Kenya
    John Doe Male France
    Sam Tomashi Male D.R.Congo
    Molly Akinyi Female Kenya
    John Doe Male France
    Sam Tomashi Male D.R.Congo
    Molly Akinyi Female Kenya
    John Doe Male France
    Sam Tomashi Male D.R.Congo
    Molly Akinyi Female Kenya
    John Doe Male France

    0 讨论(0)
提交回复
热议问题