@@ -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 ) {
@@ -1309,7 +1320,7 @@ var PageView = function pageView(container, pdfPage, id, scale,
1309
1320
1310
1321
this .scrollIntoView = function pageViewScrollIntoView (dest ) {
1311
1322
if (!dest ) {
1312
- div . scrollIntoView (true );
1323
+ scrollIntoView (div );
1313
1324
return ;
1314
1325
}
1315
1326
@@ -1368,16 +1379,7 @@ var PageView = function pageView(container, pdfPage, id, scale,
1368
1379
var width = Math .abs (boundingRect [0 ][0 ] - boundingRect [1 ][0 ]);
1369
1380
var height = Math .abs (boundingRect [0 ][1 ] - boundingRect [1 ][1 ]);
1370
1381
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 });
1381
1383
}, 0 );
1382
1384
};
1383
1385
@@ -2078,7 +2080,7 @@ window.addEventListener('pagechange', function pagechange(evt) {
2078
2080
var last = numVisibleThumbs > 1 ?
2079
2081
visibleThumbs .last .id : first ;
2080
2082
if (page <= first || page >= last )
2081
- thumbnail . scrollIntoView ();
2083
+ scrollIntoView (thumbnail );
2082
2084
}
2083
2085
2084
2086
}
0 commit comments