JQery easyUI 滚动分页

var s1 = new Date().getTime();
     $(document).ready(function(){
        var flag = true;
        //鼠标滑轮滚动事件的处理
        var scrollFunc=function(e){
            var s2 = new Date().getTime();
            console.log(s2);
            if(s2-s1<500) return;//控制滚轮滑动翻页的时间差
            var direct=0;
            e=e || window.event;
            if(e.wheelDelta){//IE/Opera/Chrome
                if(flag){
                    s1 = new Date().getTime();              
                    pageTurring(e.wheelDelta);
                }else{
                    flag = true;
                }
            }else if(e.detail){//Firefox
                s1 = new Date().getTime();
                pagepageTurringFirefox(e.detail);

            }
            // ScrollText(direct);
        };

        //注册事件
        if(document.addEventListener){
            document.addEventListener('DOMMouseScroll',scrollFunc,false);
        }
        window.onmousewheel=document.onmousewheel=scrollFunc;//IE/Opera/Chrome

        //其他浏览器翻页,根据参数的进行翻页(负数为下一页,)
        function pageTurring(e){
            flag = false;
            var grid = $('#dgairbox'); 
            var options = grid.datagrid('getPager').data("pagination").options; 
            var pageNum = options.pageNumber;//当前页数 
            var total = options.total; 
            var max = Math.ceil(total/options.pageSize);

            if(e<0){
                $('#dgairbox').datagrid('gotoPage', {
                    page: pageNum+1 > max ? 1:pageNum+1,
                    callback: function(page){
                        // console.log(page);
                    }
                });
            }else if(e>0){
                $('#dgairbox').datagrid('gotoPage', {
                    page: pageNum-1 <= 0 ? max:pageNum-1,
                    callback: function(page){
                        //console.log(page);
                    }
                });
            }
        }
        //火狐翻页,根据参数的进行翻页(正数为下一页,)
        function pagepageTurringFirefox(e){
            var grid = $('#dgairbox'); 
                var options = grid.datagrid('getPager').data("pagination").options; 
            var pageNum = options.pageNumber;//当前页数 
            var total = options.total; 
            var max = Math.ceil(total/options.pageSize);
            if(e>0){
                $('#dgairbox').datagrid('gotoPage', {
                    page: pageNum+1 > max ? 1:pageNum+1,
                    callback: function(page){
                        // console.log(page);
                    }
                });
            }else if(e<0){
                $('#dgairbox').datagrid('gotoPage', {
                    page: pageNum-1 <= 0 ? max:pageNum-1,
                    callback: function(page){
                        //console.log(page);
                    }
                });
            }
        }
    });

posted @ 2018-06-23 15:25  Eric_5279  阅读(499)  评论(0编辑  收藏  举报