根据业务定制的一个本地分页插件

来源:互联网 发布:mts钢结构设计软件 编辑:程序博客网 时间:2024/05/29 02:04
<!-- 展示层 --><div class="my-gift pull-down-cont" id="showMyGiftContent" style="width:310px;display: none;background:#fff;font-size:16px;zoom:2;">    <h3>        我的奖品        <a style="float:right; font-weight: inherit;margin-right: 9px;font: 30px/30px \5b8b\4f53,tahoma,arial;text-decoration: none; color:#000"           href="javascript:showDialog.hide();">×</a>    </h3>    <ul style="margin: 8px 26px 6px 0;list-style: none;padding: 0;">        <li style="line-height: 25px;margin-top: 8px;height: 29px;border-bottom: 1px dashed #219AFC;">            <span style="font-weight:bold;">获奖时间</span>            <span style="font-weight:bold;padding-left:112px;">所获礼包</span>        </li>    </ul>    <ul  id="getGiftContent" style="margin: 8px 0 10px 0;list-style: none;padding: 0;">    </ul></div>

(function (w) {    w.giftPageShow = null;    w.giftPageShow = function (config) {        var PageTool = {            config: function (configObj) {                for (var name in configObj) {                    if (typeof this.page[name] != 'undefined') {                        this.page[name] = configObj[name];                    } else {                        this[name] = configObj[name];                    }                }            },            page: {                giftList: null,                curGifts: null,                total: 0,                size: 8,                pageNum: 1,                curPage: 1,                prevPage: 0,                nextPage: 0,                toEnd: false            },            init: function (myGiftList) {                this.page.giftList = myGiftList;                this.page.total = len = myGiftList.length;                this.page.pageNum = Math.ceil(this.page.total / this.page.size);                $('#' + this.prev).on('click', this.prevEvent(this));                $('#' + this.next).on('click', this.nextEvent(this));                this.page.curGifts = this.page.giftList.slice(0, this.page.size);                this.render(this.page.curGifts);            },            prevEvent: function (_this) {                return function () {                    if (_this.page.curPage == 1) {                        return false;                    }                    _this.page.curPage--;                    var start = (_this.page.curPage - 1) * _this.page.size;                    _this.page.curGifts = _this.page.giftList.slice(start, start + _this.page.size);                    _this.render(_this.page.curGifts);                }            },            nextEvent: function (_this) {                return function () {                    if (_this.toEnd) {                        return false;                    }                    if ((_this.page.curPage + 1) > _this.page.pageNum) {                        _this.toEnd = true;                        return false;                    }                    _this.page.toEnd = false;                    var start = _this.page.curPage * _this.page.size;                    _this.page.curGifts = _this.page.giftList.slice(start, start + _this.page.size);                    _this.page.curPage++;                    _this.render(_this.page.curGifts);                }            },            render: function (myGiftList) {                var giftT = '';                var len = myGiftList.length;                if (len) {                    for (var i = 0; i < len; i++) {                        if (myGiftList.length) {                            giftT += ' <li style="line-height: 25px;margin-top: 4px;min-height: 27px;border-bottom: 1px dashed #219AFC;">' + '<span style="font-size:14px;" class="getTime">' + myGiftList[i].dtGetPackageTime + '</span> ' + '<span style="font-size:14px;" class="packageName"> ' + myGiftList[i].sPackageName + '</span> </li>';                        }                    }                } else {                    giftT += '<li style="line-height: 40px;margin-top: 8px;height: 50px;border-bottom: 1px dashed #219AFC;"> 亲,您还没有奖品!继续加油 </li>';                }                $('#' + this.containerId).empty();                $('#' + this.containerId).append(giftT);                need("biz.dialog", function (Dialog) {                    Dialog.show({id: 'showMyGiftContent', bgcolor: '#000', opacity: 50});                });            }        }        PageTool.config(config);        PageTool.init(config.giftList);    }})(window);
//使用方法
giftPageShow({    giftList: res.myGiftList,    containerId: "getGiftContent",    width: 300,    prev: "pageprenone",    next: "pagenextnone",    size: 8});

                       
0 0