@@ -33,6 +33,17 @@ function getFileName(url) {
33
33
return url .substring (url .lastIndexOf ('/' , end ) + 1 , end );
34
34
}
35
35
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
+
36
47
var Cache = function cacheCache (size ) {
37
48
var data = [];
38
49
this .push = function cachePush (view ) {
@@ -1315,7 +1326,7 @@ var PageView = function pageView(container, pdfPage, id, scale,
1315
1326
1316
1327
this .scrollIntoView = function pageViewScrollIntoView (dest ) {
1317
1328
if (!dest ) {
1318
- div . scrollIntoView (true );
1329
+ scrollIntoView (div );
1319
1330
return ;
1320
1331
}
1321
1332
@@ -1374,16 +1385,7 @@ var PageView = function pageView(container, pdfPage, id, scale,
1374
1385
var width = Math .abs (boundingRect [0 ][0 ] - boundingRect [1 ][0 ]);
1375
1386
var height = Math .abs (boundingRect [0 ][1 ] - boundingRect [1 ][1 ]);
1376
1387
1377
- // using temporary div to scroll it into view
1378
- var tempDiv = document .createElement ('div' );
1379
- tempDiv .style .position = 'absolute' ;
1380
- tempDiv .style .left = Math .floor (x ) + 'px' ;
1381
- tempDiv .style .top = Math .floor (y ) + 'px' ;
1382
- tempDiv .style .width = Math .ceil (width ) + 'px' ;
1383
- tempDiv .style .height = Math .ceil (height ) + 'px' ;
1384
- div .appendChild (tempDiv );
1385
- tempDiv .scrollIntoView (true );
1386
- div .removeChild (tempDiv );
1388
+ scrollIntoView (div , {left : x , top : y , width : width , height : height });
1387
1389
}, 0 );
1388
1390
};
1389
1391
@@ -2084,7 +2086,7 @@ window.addEventListener('pagechange', function pagechange(evt) {
2084
2086
var last = numVisibleThumbs > 1 ?
2085
2087
visibleThumbs .last .id : first ;
2086
2088
if (page <= first || page >= last )
2087
- thumbnail . scrollIntoView ();
2089
+ scrollIntoView (thumbnail );
2088
2090
}
2089
2091
2090
2092
}
0 commit comments