1
0
Fork 0
mirror of https://github.com/mozilla/pdf.js.git synced 2025-04-26 10:08:06 +02:00

Add support for horizontal scrolling in 'scrollIntoView' in ui_utils.js

This commit is contained in:
Jonas Jenwald 2013-12-03 19:53:20 +01:00
parent 1d276b0396
commit 736c570231
2 changed files with 22 additions and 7 deletions

View file

@ -100,7 +100,8 @@ function getOutputScale(ctx) {
/**
* Scrolls specified element into view of its parent.
* element {Object} The element to be visible.
* spot {Object} The object with the top property -- offset from the top edge.
* spot {Object} An object with optional top and left properties,
* specifying the offset from the top left edge.
*/
function scrollIntoView(element, spot) {
// Assuming offsetParent is available (it's not available when viewer is in
@ -108,21 +109,32 @@ function scrollIntoView(element, spot) {
// producing the error. See also animationStartedClosure.
var parent = element.offsetParent;
var offsetY = element.offsetTop + element.clientTop;
var offsetX = element.offsetLeft + element.clientLeft;
if (!parent) {
console.error('offsetParent is not set -- cannot scroll');
return;
}
while (parent.clientHeight == parent.scrollHeight) {
while (parent.clientHeight === parent.scrollHeight) {
if (parent.dataset._scaleY) {
offsetY /= parent.dataset._scaleY;
offsetX /= parent.dataset._scaleX;
}
offsetY += parent.offsetTop;
offsetX += parent.offsetLeft;
parent = parent.offsetParent;
if (!parent)
if (!parent) {
return; // no need to scroll
}
}
if (spot) {
if (spot.top !== undefined) {
offsetY += spot.top;
}
if (spot.left !== undefined) {
offsetX += spot.left;
parent.scrollLeft = offsetX;
}
}
if (spot)
offsetY += spot.top;
parent.scrollTop = offsetY;
}