Spaces:
Running
Running
Update reader.html
Browse files- reader.html +68 -171
reader.html
CHANGED
|
@@ -26,16 +26,24 @@
|
|
| 26 |
align-items: center;
|
| 27 |
}
|
| 28 |
|
| 29 |
-
#
|
|
|
|
| 30 |
width: 100%;
|
| 31 |
height: auto;
|
| 32 |
transform-origin: center center;
|
| 33 |
-
transition:
|
| 34 |
cursor: grab;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
}
|
| 36 |
|
| 37 |
@media (min-width: 768px) {
|
| 38 |
-
#
|
| 39 |
height: 90vh;
|
| 40 |
width: auto;
|
| 41 |
}
|
|
@@ -79,11 +87,6 @@
|
|
| 79 |
text-align: center;
|
| 80 |
z-index: 1;
|
| 81 |
width: 210px;
|
| 82 |
-
@media (orientation: portrait) {
|
| 83 |
-
transform: translate(50px, 0px);
|
| 84 |
-
}
|
| 85 |
-
|
| 86 |
-
z-index: 1;
|
| 87 |
}
|
| 88 |
|
| 89 |
#page-input:focus {
|
|
@@ -119,7 +122,8 @@
|
|
| 119 |
<div id="reader-container">
|
| 120 |
<div id="page-number"></div>
|
| 121 |
<input id="page-input" type="number" placeholder="Introdu pagina" oninput="handlePageInput(this.value)">
|
| 122 |
-
<img id="page-image" src="pages/1.jpg" alt="Pagina 1"
|
|
|
|
| 123 |
<div id="loading-message">Imaginea se încarcă, vă rog așteptați</div>
|
| 124 |
</div>
|
| 125 |
|
|
@@ -130,184 +134,77 @@
|
|
| 130 |
|
| 131 |
<script>
|
| 132 |
const TOTAL_PAGES = 92;
|
| 133 |
-
let currentPage = 1;
|
| 134 |
-
const
|
| 135 |
-
const
|
| 136 |
-
const
|
| 137 |
-
const
|
| 138 |
-
const
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
const
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
}
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
nextButton.disabled = currentPage === TOTAL_PAGES;
|
| 168 |
-
const pageNumber = currentPage * 2 + 1;
|
| 169 |
-
pageNumberElement.textContent = `${pageNumber - 1}-${pageNumber}`;
|
| 170 |
-
imageElement.style.display = 'none';
|
| 171 |
-
loadingMessage.style.display = 'block';
|
| 172 |
-
|
| 173 |
-
// Preload next and previous 2 pages
|
| 174 |
-
const pagesToPreload = [
|
| 175 |
-
currentPage - 1, currentPage, currentPage + 1,
|
| 176 |
-
currentPage + 2, currentPage + 3,
|
| 177 |
-
currentPage - 2, currentPage - 3
|
| 178 |
-
];
|
| 179 |
-
const uniquePages = pagesToPreload
|
| 180 |
-
.filter(page => page >= 1 && page <= TOTAL_PAGES)
|
| 181 |
-
.map(page => Math.floor(page))
|
| 182 |
-
.filter((value, index, self) => self.indexOf(value) === index);
|
| 183 |
-
|
| 184 |
-
preload(uniquePages);
|
| 185 |
-
};
|
| 186 |
-
|
| 187 |
-
imageElement.onload = () => {
|
| 188 |
-
imageElement.style.display = 'block';
|
| 189 |
-
loadingMessage.style.display = 'none';
|
| 190 |
-
};
|
| 191 |
-
|
| 192 |
-
prevButton.addEventListener('click', () => {
|
| 193 |
-
if (currentPage > 1) {
|
| 194 |
-
currentPage--;
|
| 195 |
-
updatePage();
|
| 196 |
-
}
|
| 197 |
-
});
|
| 198 |
-
|
| 199 |
-
nextButton.addEventListener('click', () => {
|
| 200 |
-
if (currentPage < TOTAL_PAGES) {
|
| 201 |
-
currentPage++;
|
| 202 |
-
updatePage();
|
| 203 |
-
}
|
| 204 |
-
});
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
let scale = 1;
|
| 208 |
-
const zoomStep = 0.1;
|
| 209 |
-
const maxScale = 3;
|
| 210 |
-
const minScale = 1;
|
| 211 |
-
let translateX = 0;
|
| 212 |
-
let translateY = 0;
|
| 213 |
-
|
| 214 |
-
const zoom = (delta) => {
|
| 215 |
-
scale = Math.min(maxScale, Math.max(minScale, scale + delta));
|
| 216 |
-
applyTransform();
|
| 217 |
};
|
| 218 |
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
imageElement.addEventListener('wheel', (e) => {
|
| 224 |
-
e.preventDefault();
|
| 225 |
-
zoom(e.deltaY < 0 ? zoomStep : -zoomStep);
|
| 226 |
-
});
|
| 227 |
-
|
| 228 |
-
let startX = 0;
|
| 229 |
-
let startY = 0;
|
| 230 |
-
let isDragging = false;
|
| 231 |
-
|
| 232 |
-
imageElement.addEventListener('mousedown', (e) => {
|
| 233 |
-
e.preventDefault();
|
| 234 |
-
startX = e.clientX;
|
| 235 |
-
startY = e.clientY;
|
| 236 |
-
isDragging = true;
|
| 237 |
-
imageElement.style.cursor = 'grabbing';
|
| 238 |
-
});
|
| 239 |
-
|
| 240 |
-
window.addEventListener('mousemove', (e) => {
|
| 241 |
-
if (isDragging) {
|
| 242 |
-
const dx = e.clientX - startX;
|
| 243 |
-
const dy = e.clientY - startY;
|
| 244 |
-
translateX += dx / scale;
|
| 245 |
-
translateY += dy / scale;
|
| 246 |
-
startX = e.clientX;
|
| 247 |
-
startY = e.clientY;
|
| 248 |
-
applyTransform();
|
| 249 |
}
|
| 250 |
});
|
| 251 |
|
| 252 |
-
|
| 253 |
-
|
| 254 |
-
|
| 255 |
-
});
|
| 256 |
-
|
| 257 |
-
let touchStartDistance = 0;
|
| 258 |
-
imageElement.addEventListener('touchstart', (e) => {
|
| 259 |
-
if (e.touches.length === 2) {
|
| 260 |
-
e.preventDefault();
|
| 261 |
-
touchStartDistance = Math.hypot(
|
| 262 |
-
e.touches[0].clientX - e.touches[1].clientX,
|
| 263 |
-
e.touches[0].clientY - e.touches[1].clientY
|
| 264 |
-
);
|
| 265 |
-
} else if (e.touches.length === 1) {
|
| 266 |
-
startX = e.touches[0].clientX;
|
| 267 |
-
startY = e.touches[0].clientY;
|
| 268 |
-
isDragging = true;
|
| 269 |
}
|
| 270 |
});
|
| 271 |
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
);
|
| 279 |
-
const delta = (currentDistance - touchStartDistance) / 100;
|
| 280 |
-
zoom(delta);
|
| 281 |
-
touchStartDistance = currentDistance;
|
| 282 |
-
} else if (e.touches.length === 1 && isDragging) {
|
| 283 |
-
e.preventDefault();
|
| 284 |
-
const dx = e.touches[0].clientX - startX;
|
| 285 |
-
const dy = e.touches[0].clientY - startY;
|
| 286 |
-
translateX += dx / scale;
|
| 287 |
-
translateY += dy / scale;
|
| 288 |
-
startX = e.touches[0].clientX;
|
| 289 |
-
startY = e.touches[0].clientY;
|
| 290 |
-
applyTransform();
|
| 291 |
}
|
| 292 |
});
|
| 293 |
|
| 294 |
-
|
| 295 |
-
isDragging = false;
|
| 296 |
-
});
|
| 297 |
-
|
| 298 |
function handlePageInput(value) {
|
| 299 |
const pageNumber = parseInt(value);
|
| 300 |
if (!isNaN(pageNumber)) {
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
}
|
| 306 |
-
updatePage();
|
| 307 |
}
|
| 308 |
}
|
| 309 |
|
| 310 |
-
|
|
|
|
| 311 |
</script>
|
| 312 |
</body>
|
| 313 |
-
</html>
|
|
|
|
| 26 |
align-items: center;
|
| 27 |
}
|
| 28 |
|
| 29 |
+
#page-image, #next-page-image {
|
| 30 |
+
position: absolute;
|
| 31 |
width: 100%;
|
| 32 |
height: auto;
|
| 33 |
transform-origin: center center;
|
| 34 |
+
transition: opacity 0.2s ease;
|
| 35 |
cursor: grab;
|
| 36 |
+
opacity: 1;
|
| 37 |
+
z-index: 1;
|
| 38 |
+
}
|
| 39 |
+
|
| 40 |
+
#next-page-image {
|
| 41 |
+
opacity: 0;
|
| 42 |
+
z-index: 0;
|
| 43 |
}
|
| 44 |
|
| 45 |
@media (min-width: 768px) {
|
| 46 |
+
#page-image, #next-page-image {
|
| 47 |
height: 90vh;
|
| 48 |
width: auto;
|
| 49 |
}
|
|
|
|
| 87 |
text-align: center;
|
| 88 |
z-index: 1;
|
| 89 |
width: 210px;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
}
|
| 91 |
|
| 92 |
#page-input:focus {
|
|
|
|
| 122 |
<div id="reader-container">
|
| 123 |
<div id="page-number"></div>
|
| 124 |
<input id="page-input" type="number" placeholder="Introdu pagina" oninput="handlePageInput(this.value)">
|
| 125 |
+
<img id="page-image" src="pages/1.jpg" alt="Pagina 1">
|
| 126 |
+
<img id="next-page-image" src="" alt="" style="display: none;">
|
| 127 |
<div id="loading-message">Imaginea se încarcă, vă rog așteptați</div>
|
| 128 |
</div>
|
| 129 |
|
|
|
|
| 134 |
|
| 135 |
<script>
|
| 136 |
const TOTAL_PAGES = 92;
|
| 137 |
+
let currentPage = 1;
|
| 138 |
+
const currentImageElement = document.getElementById('page-image');
|
| 139 |
+
const nextPageImageElement = document.getElementById('next-page-image');
|
| 140 |
+
const prevButton = document.getElementById('prev-button');
|
| 141 |
+
const nextButton = document.getElementById('next-button');
|
| 142 |
+
const pageNumberElement = document.getElementById('page-number');
|
| 143 |
+
const loadingMessage = document.getElementById('loading-message');
|
| 144 |
+
|
| 145 |
+
// Function to update the displayed page with cross-fade
|
| 146 |
+
const updatePage = (newPage) => {
|
| 147 |
+
currentPage = newPage;
|
| 148 |
+
prevButton.disabled = currentPage === 1;
|
| 149 |
+
nextButton.disabled = currentPage === TOTAL_PAGES;
|
| 150 |
+
|
| 151 |
+
const pageNumber = currentPage * 2 + 1;
|
| 152 |
+
pageNumberElement.textContent = `${pageNumber - 1}-${pageNumber}`;
|
| 153 |
+
|
| 154 |
+
// Load the new image into the next image element
|
| 155 |
+
nextPageImageElement.src = `pages/${currentPage}.jpg`;
|
| 156 |
+
nextPageImageElement.alt = `Pagina ${currentPage}`;
|
| 157 |
+
|
| 158 |
+
// Start the cross-fade transition
|
| 159 |
+
currentImageElement.style.opacity = '0';
|
| 160 |
+
nextPageImageElement.style.opacity = '1';
|
| 161 |
+
nextPageImageElement.style.zIndex = '2';
|
| 162 |
+
|
| 163 |
+
setTimeout(() => {
|
| 164 |
+
// Swap the images
|
| 165 |
+
[currentImageElement.src, nextPageImageElement.src] = [nextPageImageElement.src, ''];
|
| 166 |
+
currentImageElement.style.opacity = '1';
|
| 167 |
+
currentImageElement.style.zIndex = '1';
|
| 168 |
+
nextPageImageElement.style.opacity = '0';
|
| 169 |
+
nextPageImageElement.style.zIndex = '0';
|
| 170 |
+
}, 200); // Match the transition duration (0.2s)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 171 |
};
|
| 172 |
|
| 173 |
+
// Event listeners for buttons
|
| 174 |
+
prevButton.addEventListener('click', () => {
|
| 175 |
+
if (currentPage > 1) {
|
| 176 |
+
updatePage(currentPage - 1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 177 |
}
|
| 178 |
});
|
| 179 |
|
| 180 |
+
nextButton.addEventListener('click', () => {
|
| 181 |
+
if (currentPage < TOTAL_PAGES) {
|
| 182 |
+
updatePage(currentPage + 1);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 183 |
}
|
| 184 |
});
|
| 185 |
|
| 186 |
+
// Keyboard navigation
|
| 187 |
+
window.addEventListener('keydown', (e) => {
|
| 188 |
+
if (e.key === 'ArrowLeft' && !prevButton.disabled) {
|
| 189 |
+
prevButton.click();
|
| 190 |
+
} else if (e.key === 'ArrowRight' && !nextButton.disabled) {
|
| 191 |
+
nextButton.click();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 192 |
}
|
| 193 |
});
|
| 194 |
|
| 195 |
+
// Handle page input
|
|
|
|
|
|
|
|
|
|
| 196 |
function handlePageInput(value) {
|
| 197 |
const pageNumber = parseInt(value);
|
| 198 |
if (!isNaN(pageNumber)) {
|
| 199 |
+
let newPage = Math.ceil(pageNumber / 2);
|
| 200 |
+
if (newPage < 1) newPage = 1;
|
| 201 |
+
if (newPage > TOTAL_PAGES) newPage = TOTAL_PAGES;
|
| 202 |
+
updatePage(newPage);
|
|
|
|
|
|
|
| 203 |
}
|
| 204 |
}
|
| 205 |
|
| 206 |
+
// Initialize the first page
|
| 207 |
+
updatePage(1);
|
| 208 |
</script>
|
| 209 |
</body>
|
| 210 |
+
</html>
|