Home Web Front-end JS Tutorial Fixed table header makes the form scroll horizontally

Fixed table header makes the form scroll horizontally

Apr 16, 2018 pm 04:56 PM
table Horizontal form

This time I will bring you the fixed table header to make the form scroll horizontally, and the fixed table header to make the form scroll horizontally. 1. The header is wrapped with a table and wrapped with p, and the specific content of

table

is wrapped with a table 2. Use positon: relative to position the p outside the head

3. Get the height of the entire table

4. Get the distance between the DOM of the table (or the DOM wrapping the table) and the top of the page offsetTop

5. The distance between the zero point of scrolling, the height of the table, and the distance between the table and the top of the page. If the scroll exceeds this, the top value of the head will be returned to 0 or left unchanged. Of course, there are many areas that can be optimized. Just showing a little idea hehehe

Off topic, why do you use red meter? Because it is conspicuous. Haha

JS Code

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

/**

     * 最重要的一点是头和身体是两个table 然后定位用relative 然后通过滚动来计算

     * */

      function FixedHead (){

        if( !(this instanceof FixedHead) ){

          return new FixedHead()

        };

        this.$dom = $('.dataTables_scrollHead'); // 表头外层dom

        this.offsetTop = this.$dom.offset().top; // 表头外层dom距离顶部的高度

        this.parents = this.$dom.parents('.dataTables_scroll'); // 表头外层dom最外面的盒子(包裹着table的盒子)

        this.outBoxHeight = this.parents.height(); // 表头外层dom最外面的盒子(包裹着table的盒子)的高度

        this.maxHeight = this.offsetTop + this.outBoxHeight; // 滚动的零界点 最多能滚动到哪里

        this.scroll();

      }

      FixedHead.prototype = {

        constructor: FixedHead,

        scroll: function(){

          var that = this;

          $(window).scroll(function(){

            var scrollTop = $(this).scrollTop();

            if((scrollTop > that.offsetTop) && (scrollTop < that.maxHeight)){

              that.$dom.css('top', (scrollTop - that.offsetTop + 50)+'px'// 这个50是因为我的头部导航固定在顶部 高是50 所以要加上

            }else {

              var topCss = that.$dom.css('top');

              if(topCss === '0px' || topCss === 'auto'){

              }else {

                that.$dom.css('top''0px')

              }

            }

          })

        }

      }

Copy after login

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the php Chinese website! Recommended reading:

Bootstrap drop-down plug-in dropdown usage tips

Detailed explanation of tofixed and round usage in JS

AngularJS makes input box character limit reminder

The above is the detailed content of Fixed table header makes the form scroll horizontally. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Article Tags

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to implement page jump after PHP form submission How to implement page jump after PHP form submission Aug 12, 2023 am 11:30 AM

How to implement page jump after PHP form submission

How to handle user rights management in PHP forms How to handle user rights management in PHP forms Aug 10, 2023 pm 01:06 PM

How to handle user rights management in PHP forms

How to use JavaScript to implement real-time verification of the input box content of a form? How to use JavaScript to implement real-time verification of the input box content of a form? Oct 18, 2023 am 08:47 AM

How to use JavaScript to implement real-time verification of the input box content of a form?

How to use JavaScript to realize the automatic prompt function of the input box content of the form? How to use JavaScript to realize the automatic prompt function of the input box content of the form? Oct 20, 2023 pm 04:01 PM

How to use JavaScript to realize the automatic prompt function of the input box content of the form?

PHP form processing: form data query and filtering PHP form processing: form data query and filtering Aug 07, 2023 pm 06:17 PM

PHP form processing: form data query and filtering

How to use HTML, CSS and jQuery to realize the advanced function of automatic saving of forms How to use HTML, CSS and jQuery to realize the advanced function of automatic saving of forms Oct 28, 2023 am 08:20 AM

How to use HTML, CSS and jQuery to realize the advanced function of automatic saving of forms

How to create a form with a floating prompt using HTML, CSS and jQuery How to create a form with a floating prompt using HTML, CSS and jQuery Oct 25, 2023 am 10:48 AM

How to create a form with a floating prompt using HTML, CSS and jQuery

Tips for using Laravel form classes: ways to improve efficiency Tips for using Laravel form classes: ways to improve efficiency Mar 11, 2024 pm 12:51 PM

Tips for using Laravel form classes: ways to improve efficiency

See all articles