This commit is contained in:
leejinseok
2020-02-20 12:26:57 +09:00
parent cb2a736957
commit 32d05d71dc

View File

@@ -22,24 +22,24 @@ export default function (currentPage, totalPage, chapterSize = 5) {
// currentPage 2 => left -1, right +3 // currentPage 2 => left -1, right +3
const halfOfChapterSize = Math.ceil(chapterSize / 2); const halfOfChapterSize = Math.ceil(chapterSize / 2);
const halfOfLastChapter = totalPage - halfOfChapterSize + 1; const halfOfLastChapter = totalPage - halfOfChapterSize;
let extra = chapterSize - 1; let extra = chapterSize - 1;
let start; let start;
let end; let end;
if (currentPage < halfOfChapterSize) { if (currentPage < halfOfChapterSize) {
start = currentPage + (1 - currentPage); start = currentPage + (1 - currentPage);
end = currentPage + halfOfChapterSize + (halfOfChapterSize - currentPage); end = currentPage + halfOfChapterSize + (halfOfChapterSize - currentPage);
} else if (currentPage > halfOfLastChapter) { } else if (currentPage > halfOfLastChapter) {
// halfOfLastChapter = 14; let remainExtra = extra - (totalPage - currentPage);
extra = extra - (totalPage - currentPage);
start = currentPage + (totalPage - currentPage); start = currentPage + (totalPage - currentPage);
end = currentPage - extra; end = currentPage - remainExtra;
} else { } else {
start = currentPage - extra / 2; start = currentPage - extra / 2;
end = currentPage + (extra / 2); end = currentPage + (extra / 2);
console.log(start,end); end++;
} }
// currentPage 12 // currentPage 12