diff --git a/js/dom.js b/js/dom.js index 2dab18f7..7e218853 100644 --- a/js/dom.js +++ b/js/dom.js @@ -89,14 +89,14 @@ function onDOMready() { } -function scrollElementIntoView(element) { +function scrollElementIntoView(element, {invalidMarginRatio = .25} = {}) { // align to the top/bottom of the visible area if wasn't visible - const bounds = element.getBoundingClientRect(); - const boundsContainer = element.parentNode.getBoundingClientRect(); + const {top, height} = element.getBoundingClientRect(); + const {top: parentTop, bottom: parentBottom} = element.parentNode.getBoundingClientRect(); const windowHeight = window.innerHeight; - if (bounds.top < Math.max(boundsContainer.top, windowHeight / 4) || - bounds.top > Math.min(boundsContainer.bottom, windowHeight) - bounds.height - windowHeight / 4) { - window.scrollBy(0, bounds.top - windowHeight / 2 + bounds.height); + if (top < Math.max(parentTop, windowHeight * invalidMarginRatio) || + top > Math.min(parentBottom, windowHeight) - height - windowHeight * invalidMarginRatio) { + window.scrollBy(0, top - windowHeight / 2 + height); } } diff --git a/manage/manage.js b/manage/manage.js index 230e14a4..9d53d3e5 100644 --- a/manage/manage.js +++ b/manage/manage.js @@ -406,7 +406,7 @@ function handleUpdate(style, {reason, method} = {}) { filterAndAppend({entry}); if (!entry.matches('.hidden') && reason !== 'import') { animateElement(entry); - scrollElementIntoView(entry); + scrollElementIntoView(entry, {invalidMarginRatio: 0}); } function handleToggledOrCodeOnly() {