From 480d7e895519fd3be11f1c5407b2f28b554c2bb5 Mon Sep 17 00:00:00 2001 From: Koen Lageveen Date: Mon, 1 Mar 2021 20:47:07 +0100 Subject: [PATCH] only scroll to font if it's out of view --- index.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/index.js b/index.js index 63f8904..7825cfb 100644 --- a/index.js +++ b/index.js @@ -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(); + } } }