Skip to content

Commit

Permalink
fix: 缩小时,调整页码的位置不对的 bug
Browse files Browse the repository at this point in the history
  • Loading branch information
NicoKam committed May 22, 2024
1 parent a380251 commit afc7e78
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 3 additions & 1 deletion packages/pdf-viewer/src/PDFViewer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -291,8 +291,10 @@ const PDFViewer = React.forwardRef<PDFViewerHandle, PDFViewerProps>((props, pRef
const dom = pageContainerRef.current;
if (dom) {
const top = pageTopArr[page];
const height = viewports[page]?.height * scale * PixelsPerInch.PDF_TO_CSS_UNITS;
const containerHeight = dom.getBoundingClientRect().height;
dom.scrollTo({
top,
top: Math.min(top, top + 0.5 * (height - containerHeight)),
behavior: anim ? 'smooth' : 'auto',
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ const ZoomAndPageController = (props: ZoomAndPageControllerProps) => {
}
}}
onChange={(value) => {
if (!Number.isNaN(Number(value) - 1)) {
pdfViewer.changePage(Number(value) - 1);
const newPage = Number(value) - 1;
if (!Number.isNaN(newPage) && pdfViewer.getCurrentPage() !== newPage) {
pdfViewer.changePage(newPage);
}
}}
/>
Expand Down

0 comments on commit afc7e78

Please sign in to comment.