Some projects have relatively simple business, but front-end paging is used frequently. The size of the plug-in is difficult to control and it is troublesome to use, so I write a simple one myself. Implementation ideas Use jQuery.slice() to select the interval elements of the subset, and then control the display and hiding; Effect DemonstrationDemo Code <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Front-end paging implementation demo</title> </head> <body> <div class="parent"> <ul class="box" style="min-height: 147px;"> </ul> <div class="page-box"> <button class="page-btn prev">Previous page</button> <span class="page-num">1/1</span> <button class="page-btn next">Next page</button> </div> </div> <div class="parent"> <ul class="box2" style="min-height: 63px;"> </ul> <div class="page-box"> <button class="page-btn prev">Previous page</button> <span class="page-num">1/1</span> <button class="page-btn next">Next page</button> </div> </div> <script src="https://cdn.bootcdn.net/ajax/libs/jquery/3.5.1/jquery.min.js"></script> <script> /** * Paging initialization* @param {*}eleBox the container to be paged* @param {*}size the number of entries per page*/ function InitPagination(eleBox, size) { var box = $(eleBox), children = box.children(), total = children.length, pageBox = box.next(), pageNum = pageBox.find('.page-num'), maxNum = !Math.ceil(total / size) ? 1 : Math.ceil(total / size); pageNum.text('1/' + maxNum); children.hide(); children.slice(0, size).show(); pageBox.off().on('click', '.prev, .next', function (e) { var nowNum = parseInt(pageNum.text().split('/')[0]); if ($(this).hasClass('prev')) { nowNum--; if (nowNum < 1) { nowNum = 1 return; } } else { nowNum++; if (nowNum > maxNum) { nowNum = maxNum return; } } children.hide(); children.slice(size * (nowNum - 1), nowNum * size).show(); pageNum.text(nowNum + '/' + maxNum); }) } // Simulate data writing var box = $('.box'), box2 = $('.box2'), li = ''; for (let i = 0; i < 16; i++) { li += '<li>' + i + '</li>' } box.html(li); box2.html(li); // Instantiate the paginator new InitPagination(box, 7) new InitPagination(box2, 3) </script> </body> </html> 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. You may also be interested in:
|
<<: MYSQL master-slave replication knowledge points summary
>>: How to purchase and initially build a server
It has to be said that a web designer is a general...
Preparation: 1. Install VMware workstation softwa...
MySQL supports many data types, and choosing the ...
Download the MySQL installer Official download ad...
Table of contents What is axios? Axios request ty...
1. What is Docker Swarm? Docker Swarm is a cluste...
Method 1: INSERT INTO t1(field1,field2) VALUE(v00...
This may be an issue that is easily overlooked. F...
Table of contents Preface –link Custom Network As...
In HTML, you need to specify the encoding used by...
Let's talk about some problems I have encounte...
I recently used the ssm framework when doing a pr...
Introduction: Nginx (pronounced the same as engin...
Table of contents Identifier length limit Length ...
This blog is a work note environment: nginx versi...