Skip to content

Commit 9ea7c0f

Browse files
committed
Remove the scrollIntoView function
and rely on the HTMLElement.scrollIntoView function instead.
1 parent 2643125 commit 9ea7c0f

2 files changed

Lines changed: 12 additions & 46 deletions

File tree

web/pdf_viewer.js

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ import {
5757
PresentationModeState,
5858
removeNullCharacters,
5959
SCROLLBAR_PADDING,
60-
scrollIntoView,
6160
ScrollMode,
6261
SpreadMode,
6362
TextLayerMode,
@@ -1458,7 +1457,18 @@ class PDFViewer {
14581457
pageSpot = { left: 0, top: 0 };
14591458
}
14601459
}
1461-
scrollIntoView(div, pageSpot);
1460+
1461+
div.scrollIntoView({
1462+
behavior: "auto",
1463+
block: "start",
1464+
inline: pageSpot ? "start" : "nearest",
1465+
});
1466+
if (pageSpot?.top) {
1467+
this.container.scrollTop += pageSpot.top;
1468+
}
1469+
if (pageSpot?.left) {
1470+
this.container.scrollLeft += pageSpot.left;
1471+
}
14621472

14631473
// Ensure that the correct *initial* document position is set, when any
14641474
// OpenParameters are used, for documents with non-default Scroll/Spread

web/ui_utils.js

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -69,49 +69,6 @@ const CursorTool = {
6969
// Used by `PDFViewerApplication`, and by the API unit-tests.
7070
const AutoPrintRegExp = /\bprint\s*\(/;
7171

72-
/**
73-
* Scrolls specified element into view of its parent.
74-
* @param {HTMLElement} element - The element to be visible.
75-
* @param {Object} [spot] - An object with optional top and left properties,
76-
* specifying the offset from the top left edge.
77-
* @param {number} [spot.left]
78-
* @param {number} [spot.top]
79-
*/
80-
function scrollIntoView(element, spot) {
81-
// Assuming offsetParent is available (it's not available when viewer is in
82-
// hidden iframe or object). We have to scroll: if the offsetParent is not set
83-
// producing the error. See also animationStarted.
84-
let parent = element.offsetParent;
85-
if (!parent) {
86-
console.error("offsetParent is not set -- cannot scroll");
87-
return;
88-
}
89-
let offsetY = element.offsetTop + element.clientTop;
90-
let offsetX = element.offsetLeft + element.clientLeft;
91-
while (
92-
parent.clientHeight === parent.scrollHeight &&
93-
parent.clientWidth === parent.scrollWidth
94-
) {
95-
offsetY += parent.offsetTop;
96-
offsetX += parent.offsetLeft;
97-
98-
parent = parent.offsetParent;
99-
if (!parent) {
100-
return; // no need to scroll
101-
}
102-
}
103-
if (spot) {
104-
if (spot.top !== undefined) {
105-
offsetY += spot.top;
106-
}
107-
if (spot.left !== undefined) {
108-
offsetX += spot.left;
109-
parent.scrollLeft = offsetX;
110-
}
111-
}
112-
parent.scrollTop = offsetY;
113-
}
114-
11572
/**
11673
* Helper function to start monitoring the scroll event and converting them into
11774
* PDF.js friendly one: with scroll debounce and scroll direction.
@@ -890,7 +847,6 @@ export {
890847
ProgressBar,
891848
removeNullCharacters,
892849
SCROLLBAR_PADDING,
893-
scrollIntoView,
894850
ScrollMode,
895851
SidebarView,
896852
SpreadMode,

0 commit comments

Comments
 (0)