Pagination's GitHub address: https://github.com/gbirke/jquery_pagination
The company is using a 1.2 version, so I enrolled in 1.2.
JQuery.fn.pagination =function(MaxEntries, opts) {opts=$.extend ({iscurrentinfo:false,//Display current page information: current 1th page, total 10 pagesCurrentcls: '. Current-info ',//Current Page classItems_per_page:10,//up to a few items per pageNum_display_entries:10,//the number of pages in the middle such as 1 2 ... 5 6 7 8 9 ... 12 13 Median page is 5current_page:0,//Current PageNum_edge_entries:1,//pages of both ends 1 2...5 6 7 8 9...12 132 end pages 2Link_to: "javascript:;",//hrefPrev_text: "Prev", Next_text:"Next Page", Ellipse_text:"...",//text of the omitted number of pagesPrev_show_always:true,//always show previous pageNext_show_always:true,//always show next pageCallbackfunction(){return false;}//Callback},opts| |{}); return This. each (function() { //Code });};
We need to pass 2 parameters to the pagination method,
MaxEntries: Total number of items, required
OPTs, a variety of configuration items, are optional.
function NumPages () {} calculates the total number of pages
function Getinterval () {} Gets the number of intermediate pages here, the start and end pages, returned as an array [5,10]
function pageselected (page_id, evt) {} page link handler
function Drawlinks () {} Draw link
The key is drawlinks:
functiondrawlinks () {panel.empty ();//each draw is all redrawn varInterval = Getinterval ();//get start and end pages varNP = NumPages ();//Get Total Pages //pageselected gets to the current page, and then redraws the link varGetclickhandler =function(page_id) {return function(EVT) {returnpageselected (PAGE_ID,EVT);} } //Add a single connection varAppenditem =function(page_id, appendopts) {page_id= page_id<0?0: (page_id<np?page_id:np-1); Appendopts= $.extend ({text:page_id+1, classes: ""}, appendopts| |{}); if(page_id = = current_page) {//If this is the current page, create a span varLNK = $ ("<span class= ' current ' >" + (appendopts.text) + "</span>"); } Else{//otherwise , the hyperlink is generated varLNK = $ ("<a>" + (Appendopts.text) + "</a>"). Bind ("Click", Getclickhandler (page_id))//callback When you click the hyperlink. attr (' href ', opts.link_to.replace (/__id__/, page_id)); } if(appendopts.classes) {Lnk.addclass (appendopts.classes);}//Add ClassPanel.append (LNK);//Append the connection to the Panel } //Draw Previous Page if(Opts.prev_text && (current_page > 0 | |opts.prev_show_always)) {Appenditem (Current_page-1,{text:opts.prev_text, classes: "Prev"}); } //Draw starting point 1 2 ... if(Interval[0] > 0 && opts.num_edge_entries > 0) { varEnd = Math.min (Opts.num_edge_entries, interval[0]); for(vari=0; i<end; i++) {Appenditem (i); } if(Opts.num_edge_entries < interval[0] &&Opts.ellipse_text) { $("<span>" +opts.ellipse_text+ "</span>"). AppendTo (panel); } } //draw the middle section of the connection 5 6 7 8 9 for(varI=INTERVAL[0]; i<interval[1]; i++) {Appenditem (i); } //Draw end point ... the if(Interval[1] < NP && opts.num_edge_entries > 0) { if(Np-opts.num_edge_entries > interval[1]&&Opts.ellipse_text) { $("<span>" +opts.ellipse_text+ "</span>"). AppendTo (panel); } varBegin = Math.max (Np-opts.num_edge_entries, interval[1]); for(varI=begin; i<np; i++) {Appenditem (i); } } //Draw Next Page if(Opts.next_text && (Current_page < np-1 | |opts.next_show_always)) {Appenditem (Current_page+1,{text:opts.next_text, classes: "Next"}); } //Draw current page, total pages if(opts.iscurrentinfo) {varSinfo = ' current ' + (Current_page + 1) + ' page, total ' + NP + ' page '; $ (OPTS.CURRENTCLS). HTML (sinfo); }}
jquery Plugin Pagination.js Source interpretation