Skip to content

Commit

Permalink
Make Make zoom smoother in SimplePdfReader
Browse files Browse the repository at this point in the history
  • Loading branch information
HenestrosaDev committed Jun 14, 2024
1 parent f48b967 commit 1e858e7
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions resources/js/Components/Common/SimplePdfReader.vue
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,10 @@ const onWheel = (event) => {
const maxZoom = parseInt($zoomInput.value.max);
if (newZoom >= minZoom && newZoom <= maxZoom) {
changeZoom(newZoom);
$zoomInput.value.value = newZoom;
requestAnimationFrame(() => {
changeZoom(newZoom);
$zoomInput.value.value = newZoom;
});
}
};
Expand All @@ -201,14 +203,21 @@ const onTouchMove = (event) => {
if (event.touches.length === 2 && initialPinchDistance) {
const newDistance = getDistance(event.touches[0], event.touches[1]);
const scaleFactor = newDistance / initialPinchDistance;
const newZoom = Math.round(lastPinchScale * scaleFactor * 100);
// Make the zoom pinch smoother
const dampingFactor = 0.2;
const adjustedScaleFactor = 1 + dampingFactor * (scaleFactor - 1);
const newZoom = Math.round(lastPinchScale * adjustedScaleFactor * 100);
const minZoom = parseInt($zoomInput.value.min);
const maxZoom = parseInt($zoomInput.value.max);
if (newZoom >= minZoom && newZoom <= maxZoom) {
changeZoom(newZoom);
$zoomInput.value.value = newZoom;
requestAnimationFrame(() => {
changeZoom(newZoom);
$zoomInput.value.value = newZoom;
});
}
}
};
Expand Down

0 comments on commit 1e858e7

Please sign in to comment.