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

后端 未结 25 2537
悲&欢浪女
悲&欢浪女 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:31

    A bit late to the party, but here is an implementation that works with multiple tables on the same page and "jank" free (using requestAnimationFrame). Also there's no need to provide any width on the columns. Horizontal scrolling works as well.

    The headers are defined in a div so you are free to add any markup there (like buttons), if required. This is all the HTML that is needed:

    col 1 col 2 col 3

    https://jsfiddle.net/lloydleo/bk5pt5gs/

提交回复
热议问题