-
Notifications
You must be signed in to change notification settings - Fork 1
/
home.js
77 lines (68 loc) · 2.25 KB
/
home.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
var myFrame = document.getElementById('myFrame');
// var nextButton = document.getElementById('nextButton');
// var backButton = document.getElementById('backButton');
var prevPage = document.getElementById('prevPage');
var nextPage = document.getElementById('nextPage');
var pages = [
"src/page-1/index.html",
"src/page-2/index.html",
"src/page-3/index.html",
"src/page-4/index.html",
"src/page-5/index.html",
"src/page-6/index.html",
];
var pageIndex = 0;
var pagination = document.getElementById('pagination');
var pageNumbers = [];
function createPageNumbers() {
pages.forEach(function(page, index) {
var pageNumber = document.createElement('span');
pageNumber.classList.add('page-number');
if (index === pageIndex) {
pageNumber.classList.add('current-page');
}
pageNumber.textContent = index + 1;
pageNumber.addEventListener('click', function() {
pageIndex = index;
myFrame.src = pages[pageIndex];
updatePageButtons();
updatePageNumbers();
});
pagination.appendChild(pageNumber);
pageNumbers.push(pageNumber);
});
}
function updatePageButtons() {
if (pageIndex === 0) {
prevPage.classList.add('hidden');
} else {
prevPage.classList.remove('hidden');
}
if (pageIndex === pages.length - 1) {
nextPage.classList.add('hidden');
} else {
nextPage.classList.remove('hidden');
}
}
function updatePageNumbers() {
pageNumbers.forEach(function(pageNumber, index) {
if (index === pageIndex) {
pageNumber.classList.add('current-page');
} else {
pageNumber.classList.remove('current-page');
}
});
}
prevPage.addEventListener('click', function() {
pageIndex = Math.max(0, pageIndex - 1);
myFrame.src = pages[pageIndex];
updatePageButtons();
updatePageNumbers();
});
nextPage.addEventListener('click', function() {
pageIndex = Math.min(pages.length - 1, pageIndex + 1);
myFrame.src = pages[pageIndex];
updatePageButtons();
updatePageNumbers();
});
createPageNumbers();