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);
}
});
}
}
});
JQery easyUI 滾動分頁