-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinline_script_13.js
More file actions
171 lines (71 loc) · 2.7 KB
/
inline_script_13.js
File metadata and controls
171 lines (71 loc) · 2.7 KB
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
78
79
80
81
82
83
84
85
86
let currentPage = 1;
const totalPages = 10;
// Function to show the current page
function showPage(pageNumber) {
// Hide all pages
document.querySelectorAll('.page').forEach(page => {
page.classList.remove('active');
});
// Show the current page
document.getElementById(`page${pageNumber}`).classList.add('active');
// Update pagination buttons
updatePagination(pageNumber);
}
// Function to update pagination buttons
function updatePagination(pageNumber) {
const pagination = document.querySelector('.pagination');
pagination.innerHTML = ''; // Clear existing buttons
for (let i = 1; i <= totalPages; i++) {
const button = document.createElement('button');
button.textContent = i;
button.addEventListener('click', () => goToPage(i));
if (i === pageNumber) {
button.classList.add('active');
}
pagination.appendChild(button);
}
// Enable/disable previous/next buttons
document.querySelector('.nav-btn.prev').disabled = (pageNumber === 1);
document.querySelector('.nav-btn.next').disabled = (pageNumber === totalPages);
}
// Go to the next page
function nextPage() {
if (currentPage < totalPages) {
currentPage++;
showPage(currentPage);
}
}
// Go to the previous page
function prevPage() {
if (currentPage > 1) {
currentPage--;
showPage(currentPage);
}
}
// Go to a specific page
function goToPage(pageNumber) {
currentPage = pageNumber;
showPage(currentPage);
}
// Initialize the book
showPage(currentPage);
// Swipe functionality for mobile
let touchStartX = 0;
let touchEndX = 0;
document.querySelector('.book').addEventListener('touchstart', (e) => {
touchStartX = e.touches[0].clientX;
});
document.querySelector('.book').addEventListener('touchend', (e) => {
touchEndX = e.changedTouches[0].clientX;
handleSwipe();
});
function handleSwipe() {
const swipeThreshold = 50; // Minimum swipe distance
if (touchEndX < touchStartX - swipeThreshold) {
nextPage(); // Swipe left to go to the next page
} else if (touchEndX > touchStartX + swipeThreshold) {
prevPage(); // Swipe right to go to the previous page
}
}
// Initialize the first page and pagination
showPage(currentPage);