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

How to compile and install PHP and Nginx in Ubuntu environment

This article describes how to compile and install...

How to Easily Remove Source Installed Packages in Linux

Step 1: Install Stow In this example, we are usin...

JavaScript implements circular carousel

This article shares the specific code of JavaScri...

Tips on disabling IE8 and IE9's compatibility view mode using HTML

Starting from IE 8, IE added a compatibility mode,...

Vue+Element UI realizes the encapsulation of drop-down menu

This article example shares the specific code of ...

Web design tips on form input boxes

This article lists some tips and codes about form...

Web page experience: planning and design

1. Clarify the design direction <br />First,...

Detailed explanation of using top command to analyze Linux system performance

Introduction to Linux top command The top command...

Detailed installation and use of RocketMQ in Docker

To search for RocketMQ images, you can search on ...

How to develop Java 8 Spring Boot applications in Docker

In this article, I will show you how to develop a...

How to point the target link of a tag to iframe

Copy code The code is as follows: <iframe id=&...

Detailed troubleshooting of docker.service startup errors

Execute the following command to report an error ...

How to implement MySQL bidirectional backup

MySQL bidirectional backup is also called master-...

js realizes horizontal and vertical sliders

Recently, when I was doing a practice project, I ...