How to fix the four sides of the table to scroll up, down, left and right

How to fix the four sides of the table to scroll up, down, left and right

question:

When I was doing project statistics recently, I encountered a specific requirement, which required that when the table was scrolled up and down, the head and tail of the table were fixed; when the table was scrolled left and right, the first and last columns of the table were fixed.

It may be clearer if we first show the effect diagram:

When scrolling left and right, the two columns are fixed, and the middle part of the head and tail scrolls along.

When scrolling up and down, the head and tail are fixed, and the middle part of the first and last columns scrolls along.

Ideas:

After thinking for a long time, I found that it is basically difficult to achieve if you just use a table, and there are contradictions when scrolling up and down. Finally, I changed my mind and used div layout and table-like design to achieve this effect.

solve:

1. Overall layout: It is divided into three parts: upper, middle and lower, namely header, body and footer. Body is high. Implement up and down scrolling. Isn’t it simple? Haha.

2. Header layout: divided into left container right, left10% width left floating, container80% width left floating, right10% width left floating. Add a column-container (relative positioning) with the actual width of the data inside the container.

3. Body, footer and header.

4. Control core: Generate a div with the same width as the container (80%), and place a div with the same width as the actual data of the column-container (such as id=Scroll) inside it. To simulate left and right scroll bars.

JavaScript CodeCopy content to clipboard
  1. $( "#Scroll" ).scroll( function () {
  2.                  var scrollLeft = $( this ).scrollLeft();
  3. $( ".column-container" ).css({ "left" : -scrollLeft + "px" });
  4. });

That is, the simulated scroll bar controls the scrolling of the column-container in the header body footer. This way, the two columns are fixed when scrolling left and right, and the containers of the first and last rows also scroll.

Conclusion:

Since the code style is too lengthy to post, I will just talk about the ideas here and give it a try.

The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM.

Original URL: http://www.cnblogs.com/checccy/p/5601145.html

<<:  Solution to the problem of mysql master-slave switch canal

>>:  Javascript to achieve the drag effect of the login box

Recommend

Tutorial on how to deploy LNMP and enable HTTPS service

What is LNMP: Linux+Nginx+Mysql+(php-fpm,php-mysq...

How to set default value for datetime type in MySQL

I encountered a problem when modifying the defaul...

Examples of preview functions for various types of files in vue3

Table of contents Preface 1. Preview of office do...

What to do if you forget your mysql password

Solution to forgetting MySQL password: [root@loca...

How to implement Docker to dynamically pass parameters to Springboot projects

background Recently, some friends who are new to ...

Implementation of CSS text shadow gradually blurring effect

text-shadow Add a shadow to the text. You can add...

Brief analysis of mysql scheduled backup tasks

Introduction In a production environment, in orde...

Detailed explanation of crontab scheduled execution command under Linux

In LINUX, periodic tasks are usually handled by t...

Basic commands for MySQL database operations

1. Create a database: create data data _name; Two...

Several common methods of sending requests using axios in React

Table of contents Install and introduce axios dep...

Does the website's text still need to be designed?

Many people may ask, does the text on the website...

Detailed example of database operation object model in Spring jdbc

Detailed example of database operation object mod...