1 回答

TA貢獻(xiàn)1906條經(jīng)驗(yàn) 獲得超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);
}};
并且您必須創(chuàng)建函數(shù):
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();
}
});};
并在頁面準(zhǔn)備好時(shí)調(diào)用函數(shù)
$(document).ready(function() {
var width = window.innerWidth;
detect(width)
$(window).resize(function() {
var width = window.innerWidth;
detect(width)
});});
- 1 回答
- 0 關(guān)注
- 100 瀏覽
添加回答
舉報(bào)