only scroll to font if it's out of view

This commit is contained in:
Koen Lageveen 2021-03-01 20:47:07 +01:00
parent 8a158843bc
commit 480d7e8955
1 changed files with 19 additions and 1 deletions

View File

@ -263,9 +263,27 @@ function walk(direction) {
}
}
function isVisible(el) {
var offset = document.getElementById('filters').getBoundingClientRect().height;
var container = document.querySelector('section.select-list').getBoundingClientRect().height;
if (direction === 'up') {
if (el.getBoundingClientRect().top < offset) {
return false;
}
} else {
if (el.getBoundingClientRect().bottom > offset + container) {
return false;
}
}
return true;
}
if (target) {
target.querySelector('a').click();
target.scrollIntoView();
if (!isVisible(target)){
target.scrollIntoView();
}
}
}