1 回答
TA贡献1906条经验 获得超3个赞
首先,您必须检测您的窗口大小:
var detect = function(width) {
if (width < 576) {
callPagination(12);
} else if (width >= 576 && width < 768) {
callPagination(10);
} else if (width >= 768 && width < 992) {
callPagination(9);
} else if (width >= 992) {
callPagination(8);
}};
并且您必须创建函数:
var callPagination = function(pageSize) {
pageSize = pageSize;
pagesCount = $('.content').length;
var totalPages = Math.ceil(pagesCount / pageSize);
$('.pagination').twbsPagination({
totalPages: totalPages,
visiblePages: 3,
onPageClick: function(event, page) {
var startIndex = pageSize * (page - 1);
var endIndex = startIndex + pageSize;
$('.content')
.hide()
.filter(function() {
var idx = $(this).index();
return idx >= startIndex && idx < endIndex;
})
.show();
}
});};
并在页面准备好时调用函数
$(document).ready(function() {
var width = window.innerWidth;
detect(width)
$(window).resize(function() {
var width = window.innerWidth;
detect(width)
});});
- 1 回答
- 0 关注
- 74 浏览
添加回答
举报