• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号
您的位置:首页 > 程序设计 >jquery > jquery分页插件jquery.pagination.js使用方法解析

jquery分页插件jquery.pagination.js使用方法解析

作者:张龙豪 字体:[增加 减小] 来源:互联网

张龙豪 通过本文主要向大家介绍了jquery分页插件,jquery.pagination.js分页等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

这一款js分页使用起来很爽,自己经常用,做项目时总是要翻以前的项目看,不方便,这里就把他写出来方便自己以后粘帖,也希望能分享给大家。
参数说明

插件代码
js代码:

/**
 * This jQuery plugin displays pagination links inside the selected elements.
 *
 * @author Gabriel Birke (birke *at* d-scribe *dot* de)
 * @version 1.1
 * @param {int} maxentries Number of entries to paginate
 * @param {Object} opts Several options (see README for documentation)
 * @return {Object} jQuery Object
 */
jQuery.fn.pagination = function(maxentries, opts) {
 opts = jQuery.extend({
  items_per_page: 10,
  num_display_entries: 10,
  current_page: 0,
  num_edge_entries: 0,
  link_to: "#",
  prev_text: "Prev",
  next_text: "Next",
  ellipse_text: "...",
  prev_show_always: true,
  next_show_always: true,
  callback: function() { return false; }
 }, opts || {});

 return this.each(function() {
  /**
  * Calculate the maximum number of pages
  */
  function numPages() {
   return Math.ceil(maxentries / opts.items_per_page);
  }

  /**
  * Calculate start and end point of pagination links depending on 
  * current_page and num_display_entries.
  * @return {Array}
  */
  function getInterval() {
   var ne_half = Math.ceil(opts.num_display_entries / 2);
   var np = numPages();
   var upper_limit = np - opts.num_display_entries;
   var start = current_page > ne_half ? Math.max(Math.min(current_page - ne_half, upper_limit), 0) : 0;
   var end = current_page > ne_half ? Math.min(current_page + ne_half, np) : Math.min(opts.num_display_entries, np);
   return [start, end];
  }

  /**
  * This is the event handling function for the pagination links. 
  * @param {int} page_id The new page number
  */
  function pageSelected(page_id, evt) {
   current_page = page_id;
   drawLinks();
   var continuePropagation = opts.callback(page_id, panel);
   if (!continuePropagation) {
    if (evt.stopPropagation) {
     evt.stopPropagation();
    }
    else {
     evt.cancelBubble = true;
    }
   }
   return continuePropagation;
  }

  /**
  * This function inserts the pagination links into the container element
  */
  function drawLinks() {
   panel.empty();
   var interval = getInterval();
   var np = numPages();
   // This helper function returns a handler function that calls pageSelected with the right page_id
   var getClickHandler = function(page_id) {
    return function(evt) { return pageSelected(page_id, evt); }
   }
   // Helper function for generating a single link (or a span tag if it'S the current page)
   var appendItem = function(page_id, appendopts) {
    page_id = page_id < 0 ? 0 : (page_id < np ? page_id : np - 1); // Normalize page id to sane value
    appendopts = jQuery.extend({ text: page_id + 1, classes: "current" }, appendopts || {});
    if (page_id == current_page) {
     var lnk = $("<span class='current'>" + (appendopts.text) + "</span>");
    }
    else {
     var lnk = $("<a>" + (appendopts.text) + "</a>")
      .bind("click", getClickHandler(page_id))
      .attr('href', opts.link_to.replace(/__id__/, page_id));


    }
    if (appendopts.classes) { lnk.removeAttr('class'); lnk.addClass(appendopts.classes); }
    panel.append(lnk);
   }
   // Generate "Previous"-Link
   if (opts.prev_text && (current_page > 0 || opts.prev_show_always)) {
    appendItem(current_page - 1, { text: opts.prev_text, classes: "disabled" });
   }
   // Generate starting points
   if (interval[0] > 0 && opts.num_edge_entries > 0) {
    var end = Math.min(opts.num_edge_entries, interval[0]);
    for (var i = 0; i < end; i++) {
     appendItem(i);
    }
    if (opts.num_edge_entries < interval[0] && opts.ellipse_text) {
     jQuery("<span>" + opts.ellipse_text + "</span>").appendTo(panel);
    }
   }
   // Generate interval links
   for (var i = interval[0]; i < interval[1]; i++) {
    appendItem(i);
   }
   // Generate ending points
   if (interval[1] < np && opts.num_edge_entries > 0) {
    if (np - opts.num_edge_entries > interval[1] && opts.ellipse_text) {
     jQuery("<span>" + opts.ellipse_text + "</span>").appendTo(panel);
    }
    var begin = Math.max(np - opts.num_edge_entries, interval[1]);
    for (var i = begin; i < np; i++) {
     appendItem(i);
    }

   }
   // Generate "Next"-Link
   if (opts.next_text && (current_page < np - 1 || opts.next_show_always)) {
    appendItem(current_page + 1, { text: opts.next_text, classes: "disabled" });
   }
  }

  // Extract current_page from options
  var current_page = opts.current_page;
  // Create a sane value for maxentries and items_per_page
  maxentries = (!maxentries || maxentries < 0) ? 1 : maxentries;
  opts.items_per_page = (!opts.items_per_page || opts.items_per_page < 0) ? 1 : opts.items_per_page;
  // Store DOM element for easy access from all inner functions
  var panel = jQuery(this);
  // Attach control functions to the DOM element 
  this.selectPage = function(page_id) { pageSelected(page_id); }
  this.prevPage = function() {
   if (current_page > 0) {
    pageSelected(current_page - 1);
    return true;
   }
   else {
    return false;
   }
  }
  this.nextPage = function() {
   if (current_page < numPages() - 1) {
    pageSelected(current_page + 1);
    return true;
   }
   else {
    return false;
   }
  }
  // When all initialisation is done, draw the links
  drawLinks();
 });
}

css代码:

div.digg {padding: 3px; margin: 3px; text-align: center; font-family:Verdana; font-size:12px;}
div.digg a { border: #aaaadd 1px solid; padding:2px 5px; margin: 2px; color: #000099; text-decoration: none}
div.digg a:hover {border: #000099 1px solid; color: #000; }
div.digg a:active {border: #000099 1px solid; color: #000; }
div.digg span.current {border: #000099 1px solid; padding:2px 5px; font-weight: bold; margin: 2px; color: #fff;background-color: #000099}
div.digg span.disabled { border: #eee 1px solid; padding:2px 5px; margin: 2px; color: #ddd; padding-top: 2px;}


/*css meneame style pagination*/
div.meneame {
 padding-right: 3px; padding-left: 3px; font-size: 80%; padding-bottom: 3px; margin: 3px; color: #ff6500; padding-top: 3px; text-align: center; font-family:Verdana; font-size:12px;
}
div.meneame a {
 border-right: #ff9600 1px solid; padding-right: 7px; background-position: 50% bottom; border-top: #ff9600 1px solid; padding-left: 7px; background-image: url(meneame.jpg); padding-bottom: 5px; border-left: #ff9600 1px solid; color: #ff6500; margin-right: 3px; padding-top: 5px; border-bottom: #ff9600 1px solid; text-decoration: none
}
div.meneame a:hover {
 border-right: #ff9600 1px solid; border-top: #ff9600 1px solid; background-image: none; border-left: #ff9600 1px solid; color: #ff6500; border-bottom: #ff9600 1px solid; background-color: #ffc794
}
div.meneame a:active {
 border-right: #ff9600 1px solid; border-top: #ff9600 1px solid; background-image: none; border-left: #ff9600 1px solid; color: #ff6500; border-bottom: #ff9600 1px solid; background-color: #ffc794
}
div.meneame span.current {
 border-right: #ff6500 1px solid; padding-right: 7px; border-top: #ff6500 1px solid; padding-left: 7px; font-weight: bold; padding-bottom: 5px; border-left: #ff6500 1px solid; color: #ff6500; margin-right: 3px; padding-top: 5px; border-bottom: #ff6500 1px solid; background-color: #ffbe94
}
div.meneame span.disabled {
 border-right: #ffe3c6 1px solid; padding-right: 7px; border-top: #ffe3c6 1px solid; padding-left: 7px; padding-bottom: 5px; bo



 
分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

  • jqPaginator结合express实现分页展示内容效果第1/2页
  • jquery分页插件jquery.pagination.js使用方法解析
  • 利用JQuery写一个简单的异步分页插件
  • 基于jquery编写分页插件
  • Jquery 分页插件之Jquery Pagination
  • jQuery插件pagination实现分页特效

相关文章

  • jQuery实现的简洁下拉菜单导航效果代码
  • 使用jquery给新生的th绑定hover事件的实例
  • jQuery实现按键盘方向键翻页特效
  • jquery图形密码实现方法
  • 自定义刻度jQuery进度条及插件
  • jquery动态加载图片数据练习代码
  • 超级简单的jquery操作表格方法
  • 通过$(this)使用jQuery包装后的方法或属性
  • jQuery使用数组编写图片无缝向左滚动
  • jquery制作居中遮罩层效果分享

文章分类

  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号

最近更新的内容

    • seajs加载jquery时提示$ is not a function该怎么解决
    • 浅谈jquery中delegate()与live()
    • jquery实现点击弹出层效果的简单实例
    • jquery模拟SELECT下拉框取值效果
    • JQUERY简单按钮轮换选中效果实现方法
    • ASP.NET jQuery 实例9 通过控件hyperlink实现返回顶部效果
    • jQuery选择器_动力节点Java学院整理
    • jquery.form.js异步提交表单详解
    • jQuery插件FusionCharts绘制ScrollColumn2D图效果示例【附demo源码下载】
    • jQuery实现鼠标划过修改样式的方法

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有