@@ -73,11 +73,21 @@ function display(page, newCanvas, zoom, orientationDegrees) {
7373 }
7474}
7575
76+ function getContainerPadding ( ) {
77+ const containerStyle = getComputedStyle ( container ) ;
78+ return {
79+ top : parseFloat ( containerStyle . paddingTop ) ,
80+ right : parseFloat ( containerStyle . paddingRight ) ,
81+ bottom : parseFloat ( containerStyle . paddingBottom ) ,
82+ left : parseFloat ( containerStyle . paddingLeft )
83+ } ;
84+ }
85+
7686function getDefaultZoomRatio ( page , orientationDegrees ) {
7787 const viewport = getViewport ( page , 1 , orientationDegrees ) ;
78- const containerStyle = getComputedStyle ( container ) ;
79- const containerPadding = parseFloat ( containerStyle . paddingLeft ) + parseFloat ( containerStyle . paddingRight ) ;
80- const containerInnerWidth = container . clientWidth - containerPadding ;
88+ const containerPadding = getContainerPadding ( ) ;
89+ const containerHorizontalPadding = containerPadding . left + containerPadding . right ;
90+ const containerInnerWidth = container . clientWidth - containerHorizontalPadding ;
8191 const widthZoomRatio = containerInnerWidth / viewport . width ;
8292 return Math . max ( Math . min ( widthZoomRatio , channel . getMaxZoomRatio ( ) ) , channel . getMinZoomRatio ( ) ) ;
8393}
@@ -237,9 +247,10 @@ function renderPage(pageNumber, zoom, prerender, prerenderTrigger = 0) {
237247 textLayerDiv . hidden = true ;
238248 pageRendering = false ;
239249
250+ const containerPadding = getContainerPadding ( ) ;
240251 // zoom focus relative to page origin, rather than screen origin
241- const globalFocusX = channel . getZoomFocusX ( ) / ratio + container . scrollLeft ;
242- const globalFocusY = channel . getZoomFocusY ( ) / ratio + container . scrollTop ;
252+ const globalFocusX = channel . getZoomFocusX ( ) / ratio + container . scrollLeft - containerPadding . left ;
253+ const globalFocusY = channel . getZoomFocusY ( ) / ratio + container . scrollTop - containerPadding . top ;
243254
244255 const translationFactor = scaleFactor - 1 ;
245256 const scrollX = globalFocusX * translationFactor ;
0 commit comments