-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.js
More file actions
143 lines (124 loc) · 4.02 KB
/
Copy pathmain.js
File metadata and controls
143 lines (124 loc) · 4.02 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// Kindle-themed Personal Site - Page Navigation
document.addEventListener('DOMContentLoaded', () => {
console.log('📚 Kunal Shah - Kindle Resume Loaded');
// Page Navigation System
const pages = document.querySelectorAll('.page');
const prevBtn = document.getElementById('prev-btn');
const nextBtn = document.getElementById('next-btn');
const currentPageSpan = document.getElementById('current-page');
const totalPagesSpan = document.getElementById('total-pages');
let currentPage = 1;
const totalPages = pages.length;
// Set total pages
if (totalPagesSpan) {
totalPagesSpan.textContent = totalPages;
}
function showPage(pageNum) {
// Hide all pages
pages.forEach(page => {
page.classList.remove('active');
});
// Show target page
const targetPage = document.querySelector(`.page[data-page="${pageNum}"]`);
if (targetPage) {
targetPage.classList.add('active');
// Scroll to top of page content
targetPage.scrollTop = 0;
}
// Update current page number
currentPage = pageNum;
if (currentPageSpan) {
currentPageSpan.textContent = currentPage;
}
// Update button states
updateButtonStates();
}
function updateButtonStates() {
if (prevBtn) {
prevBtn.disabled = currentPage === 1;
}
if (nextBtn) {
nextBtn.disabled = currentPage === totalPages;
}
}
// Navigation button events
if (prevBtn) {
prevBtn.addEventListener('click', () => {
if (currentPage > 1) {
showPage(currentPage - 1);
}
});
}
if (nextBtn) {
nextBtn.addEventListener('click', () => {
if (currentPage < totalPages) {
showPage(currentPage + 1);
}
});
}
// Keyboard navigation
document.addEventListener('keydown', (e) => {
if (e.key === 'ArrowRight' || e.key === 'PageDown') {
if (currentPage < totalPages) {
showPage(currentPage + 1);
}
} else if (e.key === 'ArrowLeft' || e.key === 'PageUp') {
if (currentPage > 1) {
showPage(currentPage - 1);
}
}
});
// Touch/swipe navigation for mobile
let touchStartX = 0;
let touchEndX = 0;
const container = document.querySelector('.container');
if (container) {
container.addEventListener('touchstart', (e) => {
touchStartX = e.changedTouches[0].screenX;
}, { passive: true });
container.addEventListener('touchend', (e) => {
touchEndX = e.changedTouches[0].screenX;
handleSwipe();
}, { passive: true });
}
function handleSwipe() {
const swipeThreshold = 50;
const diff = touchStartX - touchEndX;
if (Math.abs(diff) > swipeThreshold) {
if (diff > 0 && currentPage < totalPages) {
// Swipe left - next page
showPage(currentPage + 1);
} else if (diff < 0 && currentPage > 1) {
// Swipe right - previous page
showPage(currentPage - 1);
}
}
}
// Page turn animation style
const style = document.createElement('style');
style.textContent = `
@keyframes pageFlipForward {
from {
opacity: 0;
transform: translateX(30px) rotateY(-5deg);
}
to {
opacity: 1;
transform: translateX(0) rotateY(0);
}
}
@keyframes pageFlipBack {
from {
opacity: 0;
transform: translateX(-30px) rotateY(5deg);
}
to {
opacity: 1;
transform: translateX(0) rotateY(0);
}
}
`;
document.head.appendChild(style);
// Initialize button states
updateButtonStates();
});