Skip to content

Commit 2531515

Browse files
committed
Replaces scrollIntoView
1 parent e0796ce commit 2531515

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

web/viewer.js

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,17 @@ function getFileName(url) {
3333
return url.substring(url.lastIndexOf('/', end) + 1, end);
3434
}
3535

36+
function scrollIntoView(element, spot) {
37+
var parent = element.offsetParent, offsetY = element.offsetTop;
38+
while (parent.clientHeight == parent.scrollHeight) {
39+
offsetY += parent.offsetTop;
40+
parent = parent.offsetParent;
41+
}
42+
if (spot)
43+
offsetY += spot.top;
44+
parent.scrollTop = offsetY;
45+
}
46+
3647
var Cache = function cacheCache(size) {
3748
var data = [];
3849
this.push = function cachePush(view) {
@@ -1309,7 +1320,7 @@ var PageView = function pageView(container, pdfPage, id, scale,
13091320

13101321
this.scrollIntoView = function pageViewScrollIntoView(dest) {
13111322
if (!dest) {
1312-
div.scrollIntoView(true);
1323+
scrollIntoView(div);
13131324
return;
13141325
}
13151326

@@ -1368,16 +1379,7 @@ var PageView = function pageView(container, pdfPage, id, scale,
13681379
var width = Math.abs(boundingRect[0][0] - boundingRect[1][0]);
13691380
var height = Math.abs(boundingRect[0][1] - boundingRect[1][1]);
13701381

1371-
// using temporary div to scroll it into view
1372-
var tempDiv = document.createElement('div');
1373-
tempDiv.style.position = 'absolute';
1374-
tempDiv.style.left = Math.floor(x) + 'px';
1375-
tempDiv.style.top = Math.floor(y) + 'px';
1376-
tempDiv.style.width = Math.ceil(width) + 'px';
1377-
tempDiv.style.height = Math.ceil(height) + 'px';
1378-
div.appendChild(tempDiv);
1379-
tempDiv.scrollIntoView(true);
1380-
div.removeChild(tempDiv);
1382+
scrollIntoView(div, {left: x, top: y, width: width, height: height});
13811383
}, 0);
13821384
};
13831385

@@ -2078,7 +2080,7 @@ window.addEventListener('pagechange', function pagechange(evt) {
20782080
var last = numVisibleThumbs > 1 ?
20792081
visibleThumbs.last.id : first;
20802082
if (page <= first || page >= last)
2081-
thumbnail.scrollIntoView();
2083+
scrollIntoView(thumbnail);
20822084
}
20832085

20842086
}

0 commit comments

Comments
 (0)