博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
封装了bootstrap的分页组件
阅读量:7200 次
发布时间:2019-06-29

本文共 2785 字,大约阅读时间需要 9 分钟。

hot3.png

模块代码

pagebar.js/** * 分页组件 */define(function(require, exports, module) {	var pageBarTpl = require("tpl/pagebar.html"), pageBarTplCom = juicer(pageBarTpl);	var defaultOpts = {};	var PageBar = function(options) {		if (!options.totalCount) {			return;		}		this.container = $(options.container);		this.options = $.extend({}, defaultOpts, options);		this.init();	};	PageBar.prototype = {		constructor : PageBar,		init : function() {			this.initUI();			this.initEvents();		},		initUI : function() {			var opts = this.options;			this.pageCount = parseInt((opts.totalCount + opts.pageSize - 1) / opts.pageSize);			this.container.html(pageBarTplCom.render({				pagecount : this.pageCount			}));			this.pageCount == 1 ? this.container.hide() : this.container.show();			this.currPage = 1;			this.pages = this.container.find(".page-nav");		},		initEvents : function() {			var that = this;			var opts = that.options;			that.container.on("click", "li a", function() {				var index = $(this).data("index"), page;				if (index == "previous") {					index = that.currPage - 1;				} else if (index == "next") {					index = that.currPage + 1;				}				if (index < 1 || index > that.pageCount) {					return;				}				if (index === that.currPage) {					return;				}				for (var i = 0; i < that.pages.length; i++) {					page = $(that.pages[i]);					page.removeClass("active");					if (page.find("a:first-child").data("index") === index) {						page.addClass("active");					}				}				that.currPage = index;				opts.onCallback && opts.onCallback(index);			});		},		destroy : function() {			this.container.off("click", "li a");		}	};	module.exports = PageBar;});

模板代码

/** * 分页组件 */define(function(require, exports, module){	return '
';});

调用代码

initPageBar : function(imgcount) {			var that = this;			var imgdg = $(that.dialog.node);			var opts = that.options;			that.pagebar && that.pagebar.destroy();			if (opts.pageSize >= imgcount) {				$("#img-pagebar").empty();				$("#img-pagebar").hide();			} else {				that.pagebar = new PageBar({					container : "#img-pagebar",					totalCount : imgcount,					pageSize : opts.pageSize,					onCallback : function(index) {						imgdg.find("#img-pagebar").hide();						imgdg.find(".js_loading").show();						that.getImageList({							begin : (index - 1) * opts.pageSize,							count : opts.pageSize						}, function(data) {							var images = data.images;							that.renderImageList(images, that.imgArr);							imgdg.find("#img-pagebar").show();							imgdg.find(".js_loading").hide();						});						imgdg.find(".imgdg-main").scrollTop(0);					}				});			}		},

效果演示

输入图片说明

转载于:https://my.oschina.net/jackzlz/blog/488127

你可能感兴趣的文章
NSDateFormatter设定日期格式
查看>>
抽象工厂模式-与-工厂方法模式区别
查看>>
javascript中if和switch,==和===详解
查看>>
python写api接口测试之tonador
查看>>
ibatis初识
查看>>
hdu 1950 Bridging signals
查看>>
poj - 1442 Black Box
查看>>
js replaceChild
查看>>
个人简介
查看>>
Ubuntu卡在Logo界面
查看>>
DjangoRestFramework 学习之restful规范 APIview 解析器组件 Postman等
查看>>
Ext JS 4.1 RC2 Released发布
查看>>
一个IT经理眼中的RTX、Simba2013与Lync
查看>>
mysql数据库批量插入数据shell脚本实现
查看>>
Virtual Machine Manager 2008 2008 R2系列之安装部署
查看>>
例解三层交换原理
查看>>
【灵性觉醒】解忧杂货店感悟
查看>>
"log_bin.index not found" 启动报错解决
查看>>
SFB 项目经验-36-分配公网证书 For SFB 2015-前端服务器(图解)
查看>>
SFB 项目经验-52-Outlook-2010/2013-连接Exchange 2016需要密码!
查看>>